无法解析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;
}
}
我感谢您的帮助,如果你能帮助我,谢谢:)
答
可以使用
JArray a = JArray.Parse(jsonStr);
我试图用从http://json2csharp.com/得到了类来分析你的JSON。我认为你必须分析它直接
List<RootObject> yourObject= JsonConvert.DeserializeObject<List<RootObject>>(jsonStr);
由于需要JSON对象,你可以尝试第一个选项
答
试试这个:
JArray a = JArray.Parse(jsonStr);
不要试图首先解析JObject,因为数据是一个数组,因为它以[开始并且以]结尾]。
+0
感谢它帮助了很多:) –
感谢,这是非常有帮助,我:) –