[英]Failed to Parse JSON in Windows Phone
我正在嘗試解析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 Object,您可以嘗試第一個選項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.