问题
Possible Duplicate:
JsonArray.Parse(…) error
I am developing a manga information app for Windows 8 (in C#, XAML). I'm receiving information from a public web API (http://www.mangaeden.com/api/list/0/) which I'll use in my app accordingly. I can receive the JSON string effectively but I cannot parse it correctly and I don't know what exactly is wrong with it. The error that comes up is "Invalid JSON string" but when I check on http://jsonlint.com/ it's a validated JSON String.
Everytime I run the code I get the following error:
Invalid character at position 0
Here is my code:
//Receive JSON String from MangaEden Website
var client = new HttpClient();
client.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await client.GetAsync(new Uri("http://www.mangaeden.com/api/list/0/"));
var result = await response.Content.ReadAsStringAsync();
//
// Parse the JSON data
//
var manga = JsonArray.Parse(result);
回答1:
your json is not an array it is an object containing an array, Try this:
var client = new HttpClient();
var response = await client.GetStringAsync(new Uri("http://www.mangaeden.com/api/list/0/"));
var obj = JObject.Parse(response);
var manga = obj["manga"] as JArray;
来源:https://stackoverflow.com/questions/12922040/json-parse-error-windows-8