我正在尝试解析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);
我试图使用从http://json2csharp.com/获得的Class解析您的json 。我认为您必须直接解析
List<RootObject> yourObject= JsonConvert.DeserializeObject<List<RootObject>>(jsonStr);
由于您需要Json Object,因此可以尝试第一种选择
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句