Reputation: 22994
For this code:
JObject o = JObject.Parse(jsStr);
var sel = o.SelectToken(".items[*].owner");
where the jsStr
is the content of https://api.github.com/search/repositories?q=Newtonsoft.Json&sort=stars&order=desc
I'll get the error of
Path returned multiple tokens.
How to make it works?
Upvotes: 7
Views: 9563
Reputation: 101690
The .SelectToken()
method is for querying a single (string) value. You are getting an error because that path matches 60 values, not one.
Instead, use .SelectTokens()
, which returns an IEnumerable<JToken>
:
var vals = o.SelectTokens(".items[*].owner");
Upvotes: 13