-Initial JsonPath

This commit is contained in:
James Newton-King
2013-11-15 00:20:20 +13:00
parent 12932404d4
commit d8ddf1b433
3 changed files with 484 additions and 101 deletions
+17
View File
@@ -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);