无法解析Windows Phone中的JSON

问题描述:

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

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

我试图用从http://json2csharp.com/得到了类来分析你的JSON。我认为你必须分析它直接

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

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

+0

感谢,这是非常有帮助,我:) –

试试这个:

JArray a = JArray.Parse(jsonStr); 

不要试图首先解析JObject,因为数据是一个数组,因为它以[开始并且以]结尾]。

+0

感谢它帮助了很多:) –