当前位置: 首页>>代码示例>>C#>>正文


C# JObject.Descendants方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.Descendants方法的具体用法?C# JObject.Descendants怎么用?C# JObject.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JObject的用法示例。


在下文中一共展示了JObject.Descendants方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTopic

        public IHttpActionResult AddTopic([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string TeacherId;
            string Group;
            string Title;
            string Description;
            long Date;
            string SubjectId;

            try
            {
                TeacherId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "TeacherId").Value.ToString();
                Group = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Group").Value.ToString();
                Title = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Title").Value.ToString();
                Description = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value.ToString();
                SubjectId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "SubjectId").Value.ToString();
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a field query");
            }
            catch (System.FormatException)
            {
                return Content(HttpStatusCode.NotFound, "from and size it must be non-negative integer");
            }

            _topicRepository.AddTopic(new Topic(TeacherId, Group, Title, Description, DateTime.Now.Ticks, SubjectId));
            return Ok();
        }
开发者ID:NikToloknov,项目名称:CathedralProjects,代码行数:35,代码来源:TopicController.cs

示例2: AddStage

        public IHttpActionResult AddStage([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string Author_id;
            string Project_id;
            string Title;
            string Description;
            bool State;

            try
            {
                Author_id = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Author_id").Value.ToString();
                Project_id = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Project_id").Value.ToString();
                Title = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Title").Value.ToString();
                Description = Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value.ToString();
                State = Convert.ToBoolean(Json.Descendants().OfType<JProperty>().First(p => p.Name == "Description").Value);
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a field query");
            }
            catch (System.FormatException)
            {
                return Content(HttpStatusCode.NotFound, "from and size it must be non-negative integer");
            }

            _stageRepository.AddStage(new Stage(Author_id,Project_id,Title,Description,State,DateTime.Now.Ticks));
            return Ok();
        }
开发者ID:NikToloknov,项目名称:CathedralProjects,代码行数:34,代码来源:StageController.cs

示例3: FindAllDependencyProperties

 private static IEnumerable<JProperty> FindAllDependencyProperties(JObject projectJsonRoot)
 {
     return projectJsonRoot
         .Descendants()
         .OfType<JProperty>()
         .Where(property => property.Name == "dependencies")
         .Select(property => property.Value)
         .SelectMany(o => o.Children<JProperty>());
 }
开发者ID:dsgouda,项目名称:buildtools,代码行数:9,代码来源:VisitProjectDependencies.cs

示例4: FindAllDependencyProperties

 public static IEnumerable<KeyValuePair<string, string>> FindAllDependencyProperties(JObject projectJsonObj)
 {
     return projectJsonObj
         .Descendants()
         .OfType<JProperty>()
         .Where(property => property.Name == "dependencies")
         .Select(property => property.Value)
         .SelectMany(o => o.Children<JProperty>())
         .Where(p => !p.Name.Contains("TargetingPack"))
         .Select(p => GetDependencyPair(p))
         .Where(p => !string.IsNullOrEmpty(p.Value));
 }
开发者ID:xornand,项目名称:dotnet-reliability,代码行数:12,代码来源:ProjectJsonDependencyInfo.cs

示例5: AddTopic

        public IHttpActionResult AddTopic([FromBody]string search)
        {
            JObject Json = new JObject();
            using (StreamReader sr = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                Json = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
            }

            string studentId;
            string topicId;

            try
            {
                studentId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "studentId").Value.ToString();
                topicId = Json.Descendants().OfType<JProperty>().First(p => p.Name == "topicId").Value.ToString();
            }
            catch (System.InvalidOperationException)
            {
                return Content(HttpStatusCode.NotFound, "The request must contain a all field");
            }

            _projectRepository.addProject(topicId, studentId);
            return Ok();
        }
开发者ID:NikToloknov,项目名称:CathedralProjects,代码行数:24,代码来源:ProjectController.cs

示例6: ExtractData

 public static void ExtractData(StatusData<object> result, JObject data, string errorFlag, string elementToExtract = null, ICollection<string> elementsToBypass = null)
 {
     JToken token;
     if (data.TryGetValue(errorFlag, StringComparison.OrdinalIgnoreCase, out token) && !Convert.ToBoolean(token))
     {
         if (elementToExtract != null &&
             data.TryGetValue(elementToExtract, StringComparison.OrdinalIgnoreCase, out token))
             result.Data = token.ToObject<object>();
         else
         {
             data.Descendants().OfType<JProperty>()
                 .Where(p => elementsToBypass != null && elementsToBypass.Contains(p.Name))
                 .ToList()
                 .ForEach(att => att.Remove());
             result.Data = data;
         }
     }
     else
         result.Status = SystemDbStatus.GeneralError;
 }
开发者ID:tektak-abhisheksth,项目名称:Web-API,代码行数:20,代码来源:Helper.cs

示例7: normalizeTerms

        //==============================
        //
        //==============================
        private static JObject normalizeTerms(JObject record)
        {
            var eTerms = record.Descendants().Where(o=>o.Type==JTokenType.Property && ((JProperty)o).Name=="identifier").Select(o=>o.Parent).ToArray();

            foreach(var eTerm in eTerms) {

                if(eTerm["identifier"].Type != JTokenType.String)
                {
                    if(eTerm["identifier"].Type != JTokenType.Null && eTerm["identifier"].Type != JTokenType.Undefined) {
                        Console.WriteLine("WARNING(normalizeTerms): Invalid identifier type {0} of `({2})` report\n{1}", eTerm["identifier"].Type, eTerm.Parent, getReportName(record));
                    }

                    continue;
                }

                var identifier = (string)eTerm["identifier"];
                var term = getTerm(identifier??"");

                if(term!=null)
                    eTerm["title"] = term.title;

                if(!string.IsNullOrWhiteSpace(identifier))
                    eTerm[identifier] =  eTerm.DeepClone(); // add identifier 'value' property
            }

            return record;
        }
开发者ID:scbd,项目名称:financial-resource-exporter,代码行数:30,代码来源:Program.cs

示例8: mapValues

        //==============================
        //
        //==============================
        private static IDictionary<string, object> mapValues(JObject record)
        {
            JTokenType [] types = new [] {
                //JTokenType.None,
                JTokenType.Object,
                JTokenType.Array,
                //JTokenType.Constructor,
                //JTokenType.Property,
                //JTokenType.Comment,
                JTokenType.Integer,
                JTokenType.Float,
                JTokenType.String,
                JTokenType.Boolean,
                JTokenType.Null,
                JTokenType.Undefined,
                JTokenType.Date,
                //JTokenType.Raw,
                //JTokenType.Bytes,
                //JTokenType.Guid,
                //JTokenType.Uri,
                //JTokenType.TimeSpan
            };

            Dictionary<string, object> map = new Dictionary<string,object>();

            var qValues = record.Descendants().Where(o => types.Contains(o.Type)).ToArray();

            var i=0;

            foreach(var jValue in qValues){
                Console.Write("\rMapping report values {0}%   ", ++i*100/qValues.Length);
                map.Add(jValue.Path, toXlValue(jValue));
            }

            Console.WriteLine();

            return map;
        }
开发者ID:scbd,项目名称:financial-resource-exporter,代码行数:41,代码来源:Program.cs

示例9: JsonEntityVisitor

        public static void JsonEntityVisitor(JObject root, Action<JObject> visitor)
        {
            var props = root
                .Descendants()
                .Where(t => t.Type == JTokenType.Property)
                .Cast<JProperty>()
                .Where(p => Utility.IdNames.Contains(p.Name))
                .ToList();

            foreach (var prop in props)
            {
                visitor((JObject)prop.Parent);
            }
        }
开发者ID:michaelstaib,项目名称:NuGet.Protocol,代码行数:14,代码来源:Utility.cs

示例10: FindEntityInJson

        public static async Task<JToken> FindEntityInJson(Uri entity, JObject json)
        {
            string search = entity.AbsoluteUri;

            var idNode = json.Descendants().Concat(json).Where(n =>
            {
                JProperty prop = n as JProperty;

                if (prop != null)
                {
                    string url = prop.Value.ToString();

                    return StringComparer.Ordinal.Equals(url, search);
                }

                return false;
            }).FirstOrDefault();

            if (idNode != null)
            {
                return idNode.Parent.DeepClone();
            }

            return null;
        }
开发者ID:michaelstaib,项目名称:NuGet.Protocol,代码行数:25,代码来源:Utility.cs

示例11: GetProperty

        /// <summary>
        /// Gets value of the specified property of payload
        /// </summary>
        /// <param name="payload">The payload</param>
        /// <param name="property">The name of property</param>
        /// <returns>The property value</returns>
        private static string GetProperty(JObject payload, string property)
        {
            string result = null;
            var x = from p in payload.Descendants()
                    where p is JProperty && ((JProperty)p).Name == property
                    select ((JProperty)p).Value;
            if (x.Any())
            {
                result = x.First().Value<string>();
            }

            return result;
        }
开发者ID:RongfangWang,项目名称:ValidationTool,代码行数:19,代码来源:CommonCore2014.cs


注:本文中的Newtonsoft.Json.Linq.JObject.Descendants方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。