无法在 Windows Phone 中解析 JSON



我正在尝试解析一个Json。我已经成功地将 Json 传递给字符串,但我无法将其转换为 JObject。这是我的尝试代码:

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;
   }
}

这是 JSON 的来源: http://apibiru.herokuapp.com/v0.1/feeds/1?auth_token=64d362d2e483e8023c46595f83ca8d9555ff6d7cc700a2474fbdbd341c43c1fb

如果您能帮助我,感谢您的帮助,谢谢:)

试试这个:

JArray a = JArray.Parse(jsonStr);

不要先尝试解析为 JObject,因为您的数据是一个数组,因为它以 [ 开头并以 ] 结尾。

您可以使用

JArray a = JArray.Parse(jsonStr);

我试图使用从 http://json2csharp.com/获得的类来解析您的 json。我认为您必须直接解析它

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

由于您需要 Json 对象,您可以尝试第一个选项

最新更新