當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。