当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Failed to Parse JSON in Windows Phone

问题描述:

I'm trying to parse a Json. I have successfully passed the Json onto string, but I can't convert it onto JObject. Here is my attempt code:

private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)

{

string jsonStr = e.Result;

if (!string.IsNullOrEmpty(jsonStr))

{

JObject objects = JObject.Parse(jsonStr); // this is when the error came at the first time. It says: An exception of type 'Newtonsoft.Json.JsonReaderException' occured in Newtonsoft.Json.DLL but was not handled in user code.

JArray a = (JArray)objects[""];

IList<Feeds.Topic> listFeeds = a.ToObject<IList<Feeds.Topic>>();

this.DataContext = listFeeds;

}

}

And here is the source of JSON: http://apibiru.herokuapp.com/v0.1/feeds/1?auth_token=64d362d2e483e8023c46595f83ca8d9555ff6d7cc700a2474fbdbd341c43c1fb

I appreciate your help if you can help me, thanks :)

网友答案:

you can use

JArray a = JArray.Parse(jsonStr);

I tried to parse your json using the Class that got from http://json2csharp.com/. I think you have to parse it directly

List<RootObject> yourObject= JsonConvert.DeserializeObject<List<RootObject>>(jsonStr);

Since you need Json Object you can try the first option

网友答案:

Try this instead:

JArray a = JArray.Parse(jsonStr);

Don't try to parse into a JObject first as your data is an array as it starts with [ and ends with ].

分享给朋友:
您可能感兴趣的文章:
随机阅读: