JSON解析错误(Windows 8) [英] JSON Parse Error (Windows 8)

查看:303
本文介绍了JSON解析错误(Windows 8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
JsonArray.Parse(…)错误

Possible Duplicate:
JsonArray.Parse(…) error

我正在为Windows 8(在C#,XAML中)开发一个漫画信息应用程序.我从公共Web API( http://www.mangaeden.com/api/list/0/),我将在我的应用中相应地使用它.我可以有效地接收JSON字符串,但是我无法正确解析它,而且我也不知道它到底出了什么问题.出现的错误是无效的JSON字符串",但是当我检查 http://jsonlint.com/时,它是经过验证的JSON字符串.

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:

位置0处的字符无效

这是我的代码:

//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);

推荐答案

您的json不是数组,它是包含数组的对象,请尝试以下操作:

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;

这篇关于JSON解析错误(Windows 8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆