本文整理汇总了C#中Newtonsoft.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Newtonsoft.TryGetValue方法的具体用法?C# Newtonsoft.TryGetValue怎么用?C# Newtonsoft.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft
的用法示例。
在下文中一共展示了Newtonsoft.TryGetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Matches
// Test for any true matching condition(s)
private bool Matches(Newtonsoft.Json.Linq.JObject json)
{
for (int i = 0; i < Match.Length; i += 2)
{
string field = Match[i];
string expr = Match[i + 1];
JToken token = null;
if (json.TryGetValue(field, out token))
{
string text = token.ToString();
if (!string.IsNullOrEmpty(text))
{
var resolver = new RegexGrokResolver();
var pattern = resolver.ResolveToRegex(expr);
var match = Regex.Match(text, pattern);
if (match.Success)
{
var regex = new Regex(pattern);
var namedCaptures = regex.MatchNamedCaptures(text);
foreach (string fieldName in namedCaptures.Keys)
{
AddOrModify(json, fieldName, namedCaptures[fieldName]);
}
return true; // Yes!
}
}
if (string.IsNullOrEmpty(expr))
return true; // Empty field is no match
}
}
return false; // Not specified is failure
}
示例2: ReadJson
protected override Entity ReadJson(Entity entity, Type objectType, Newtonsoft.Json.Linq.JObject json, JsonSerializer serializer)
{
var conn = base.ReadJson(entity, objectType, json, serializer) as Connection;
if (conn == null)
return null;
// Parse the relation information
// Relation id
JToken value;
if (json.TryGetValue("__relationid", out value) == true && value.Type != JTokenType.Null)
conn.RelationId = value.ToString();
// Parse the endpoints
if (json.TryGetValue("__endpointa", out value) == true && value.Type == JTokenType.Object)
conn.EndpointA = ParseEndpoint(value as JObject, serializer);
else throw new Exception(string.Format("Endpoint A for connection with id {0} is invalid.", conn.Id));
if (json.TryGetValue("__endpointb", out value) == true && value.Type == JTokenType.Object)
conn.EndpointB = ParseEndpoint(value as JObject, serializer);
else throw new Exception(string.Format("Endpoint B for connection with id {0} is invalid.", conn.Id));
return conn;
}
示例3: Matches
private bool Matches(Newtonsoft.Json.Linq.JObject json)
{
string field = Match[0];
CultureInfo ci = CultureInfo.CreateSpecificCulture(Locale);
JToken token = null;
if (json.TryGetValue(field, out token))
{
string text = token.ToString();
if (!string.IsNullOrEmpty(text))
{
DateTime ts;
var exprArray = Match.Skip(1).ToArray();
var resolver = new RegexGrokResolver();
for (int i=0; i<exprArray.Length; i++)
{
var pattern = resolver.ResolveToRegex(exprArray[i]);
exprArray[i] = pattern;
}
if (DateTime.TryParseExact(text, exprArray, ci, DateTimeStyles.None, out ts))
AddOrModify(json, ts);
}
return true; // Empty field is no match
}
return false; // Not specified is failure
}