JSON Parse Error (Windows 8) [duplicate]

风流意气都作罢 提交于 2019-12-12 04:22:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!