Failed to parse JSON in Windows Phone

I am trying to parse Json. I have successfully passed Json to a string, but I cannot convert it to a 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 JSON source: http://apibiru.herokuapp.com/v0.1/feeds/1?auth_token=64d362d2e483e8023c46595f83ca8d9555ff6d7cc700a2474fbdbd341c43c1fb

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

+3
source share
2 answers

you can use

JArray a = JArray.Parse(jsonStr);

I tried to parse your json using a class derived from http://json2csharp.com/ . I think you need to parse it directly.

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

Since you need a Json Object, you can try the first option

+1
source

:

JArray a = JArray.Parse(jsonStr);

JObject, , [ ].

+4

All Articles