Reputation: 95
I want to save "title" value from
https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=usa&redirects=true
I use this code but doesn't work:
string fileDownload;
using (WebClient client = new WebClient())
{
fileDownload = client.DownloadString("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=usa&redirects=true");
}
JObject sa = JObject.Parse(fileDownload);
string sq = sa["query"]["pages"][0]["title"].ToString();
I use [0]
after ["pages"]
because pageid changes for another page.
Upvotes: 2
Views: 85
Reputation: 8308
Try following
string sq = sa["query"]["pages"].First.First["title"].ToString();
Upvotes: 2