本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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");
}
}
}