2014-02-10 59 views
3

我試圖解析一個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

我感謝您的幫助,如果你能幫助我,謝謝:)

回答

1

可以使用

JArray a = JArray.Parse(jsonStr); 

我試圖用從http://json2csharp.com/得到了類來分析你的JSON。我認爲你必須分析它直接

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

由於需要JSON對象,你可以嘗試第一個選項

+0

感謝,這是非常有幫助,我:) –

4

試試這個:

JArray a = JArray.Parse(jsonStr); 

不要試圖首先解析JObject,因爲數據是一個數組,因爲它以[開始並且以]結尾]。

+0

感謝它幫助了很多:) –