Newtonsoft.Json/Linq/JsonPath/FieldFilter.cs
(完整代码) 1KBusing System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Linq.JsonPath
{
internal class FieldFilter : PathFilter
{
public string Name { get; set; }
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
{
foreach (JToken t in current)
{
JObject o = t as JObject;
if (o != null)
{
if (Name != null)
{
JToken v = o[Name];
if (v != null)
yield return v;
else if (errorWhenNoMatch)
throw new JsonException("Property '{0}' does not exist on JObject.".FormatWith(CultureInfo.InvariantCulture, Name));
}
else
{
foreach (KeyValuePair<string, JToken> p in o)
{
yield return p.Value;
}
}
}
else
{
if (errorWhenNoMatch)
throw new JsonException("Property '{0}' not valid on {1}.".FormatWith(CultureInfo.InvariantCulture, Name ?? "*", t.GetType().Name));
}
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。