-Initial JsonPath
This commit is contained in:
@@ -1932,6 +1932,23 @@ namespace Newtonsoft.Json.Linq
|
||||
/// <param name="errorWhenNoMatch">A flag to indicate whether an error should be thrown if no token is found.</param>
|
||||
/// <returns>The <see cref="JToken"/> that matches the object path.</returns>
|
||||
public JToken SelectToken(string path, bool errorWhenNoMatch)
|
||||
{
|
||||
JPath p = new JPath(path);
|
||||
|
||||
// todo change this to a foreach
|
||||
List<JToken> result = p.Evaluate(this, errorWhenNoMatch).ToList();
|
||||
if (result.Count > 1)
|
||||
throw new Exception("TODO");
|
||||
|
||||
return result.SingleOrDefault();
|
||||
}
|
||||
|
||||
public IEnumerable<JToken> SelectTokens(string path)
|
||||
{
|
||||
return SelectTokens(path, false);
|
||||
}
|
||||
|
||||
public IEnumerable<JToken> SelectTokens(string path, bool errorWhenNoMatch)
|
||||
{
|
||||
JPath p = new JPath(path);
|
||||
return p.Evaluate(this, errorWhenNoMatch);
|
||||
|
||||
Reference in New Issue
Block a user