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


C# JArray.FirstOrDefault方法代码示例

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


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

示例1: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
            JsonSerializer serializer)
        {
            JObject jo = JObject.Load(reader);
            var schema = JsonConvert.DeserializeObject<Schema>(jo.ToString(),
                GetSettings(serializer));

            var requiredList = new List<string>();
            //Per JSON schema 4.0, each node uses the "IsRequired" field (an array) to call out mandatory properties.
            var requiredProperties = new JArray(schema.Required);
            foreach (var requiredProperty in requiredProperties)
            {
                requiredList.Add((string) requiredProperty);
            }
            schema.Required = requiredList;
            if (schema.Properties != null)
            {
                foreach (var key in schema.Properties.Keys)
                {
                    Schema value = schema.Properties[key];
                    bool inRequiredList = (requiredProperties.FirstOrDefault(p => (string) p == key) != null);
                    value.IsRequired = inRequiredList;
                }
            }

            return schema;
        }
开发者ID:jhancock93,项目名称:autorest,代码行数:27,代码来源:SchemaRequiredItemConverter.cs

示例2: IsChildJob

        /// <summary>
        /// Is this a child build job.  If so return the ID of the parent job and base url
        /// </summary>
        internal static bool IsChildJob(JArray actions, out string baseUrl, out int parentBuildId)
        {
            baseUrl = null;
            parentBuildId = 0;

            var obj = actions.FirstOrDefault(x => x["causes"] != null);
            if (obj == null)
            {
                return false;
            }

            var array = (JArray)obj["causes"];
            if (array.Count == 0)
            {
                return false;
            }

            var data = array[0];
            baseUrl = data.Value<string>("upstreamUrl");
            parentBuildId = data.Value<int>("upstreamBuild");
            return baseUrl != null && parentBuildId != 0;
        }
开发者ID:dpoeschl,项目名称:jenkins,代码行数:25,代码来源:JsonUtil.cs

示例3: Merge

        private void Merge(JArray result, JObject outputEntry)
        {
            var existing =  result.FirstOrDefault(x => this.tableOps.IsPrimaryKeyEqual(outputEntry.AsDictionary(), ((JObject) x).AsDictionary()));

            if (existing != null)
            {
                existing.Replace(outputEntry);
            }
            else
            {
                result.Add(outputEntry);
            }
        }
开发者ID:sorvis,项目名称:DataSeeder,代码行数:13,代码来源:DumpCommand.cs

示例4: TryParsePullRequestInfo

        internal static bool TryParsePullRequestInfo(JArray actions, out PullRequestInfo info)
        {
            var container = actions.FirstOrDefault(x => x["parameters"] != null);
            if (container == null)
            {
                info = null;
                return false;
            }

            string sha1 = null;
            string pullLink = null;
            int? pullId = null;
            string pullAuthor = null;
            string pullAuthorEmail = null;
            string commitAuthorEmail = null;
            var parameters = (JArray)container["parameters"];
            foreach (var pair in parameters)
            {
                switch (pair.Value<string>("name"))
                {
                    case "ghprbActualCommit":
                        sha1 = pair.Value<string>("value") ?? sha1;
                        break;
                    case "ghprbPullId":
                        pullId = pair.Value<int>("value");
                        break;
                    case "ghprbPullAuthorLogin":
                        pullAuthor = pair.Value<string>("value") ?? pullAuthor;
                        break;
                    case "ghprbPullAuthorEmail":
                        pullAuthorEmail = pair.Value<string>("value") ?? pullAuthorEmail;
                        break;
                    case "ghprbActualCommitAuthorEmail":
                        commitAuthorEmail = pair.Value<string>("value") ?? commitAuthorEmail;
                        break;
                    case "ghprbPullLink":
                        pullLink = pair.Value<string>("value") ?? pullLink;
                        break;
                    default:
                        break;
                }
            }

            // It's possible for the pull email to be blank if the Github settings for the user 
            // account hides their public email address.  In that case fall back to the commit 
            // author.  It's generally the same value and serves as a nice backup identifier.
            if (string.IsNullOrEmpty(pullAuthorEmail))
            {
                pullAuthorEmail = commitAuthorEmail;
            }

            if (sha1 == null || pullLink == null || pullId == null || pullAuthorEmail == null)
            {
                info = null;
                return false;
            }

            info = new PullRequestInfo(
                author: pullAuthor,
                authorEmail: pullAuthorEmail,
                id: pullId.Value,
                pullUrl: pullLink,
                sha1: sha1);
            return true;
        }
开发者ID:jaredpar,项目名称:jenkins,代码行数:65,代码来源:JsonUtil.cs

示例5: LoadProfiles

 private void LoadProfiles()
 {
     if (profiles == null || profiles.Count == 0)
     {
         string data = MyGetWebData(homeUrl, true);
         Regex rgx = new Regex(@"nf\.constants\.page\.contextData =(.*); }\(netflix\)\);");
         Match m = rgx.Match(data);
         if (m.Success)
         {
             string jsonData = m.Groups[1].Value;
             JObject json = (JObject)JsonConvert.DeserializeObject(jsonData);
             profiles = json["profiles"]["data"]["allProfiles"].Value<JArray>();
             if (string.IsNullOrEmpty(ProfileName) || !profiles.Any(p => p["profileName"].Value<string>() == ProfileName))
             {
                 if (!string.IsNullOrWhiteSpace(startupUserProfile) && profiles.Any(p => p["profileName"].Value<string>() == startupUserProfile))
                 {
                     currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == startupUserProfile);
                 }
                 else
                 {
                     currentProfile = (JObject)profiles.FirstOrDefault(p => p["isAccountOwner"].Value<bool>());
                 }
             }
             else
             {
                 currentProfile = (JObject)profiles.FirstOrDefault(p => p["profileName"].Value<string>() == ProfileName);
             }
             MyGetWebData(string.Format(switchProfileUrl, apiRoot, ProfileToken), true);
         }
         else
         {
             cc = null;
             Settings.DynamicCategoriesDiscovered = false;
             Settings.Categories.Clear();
             profiles = null;
             throw new OnlineVideosException("Error loading profiles. Please try again");
         }
     }
 }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:39,代码来源:NetfilxWebUtil.cs


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