【发布时间】:2011-08-12 04:43:28
【问题描述】:
public void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs c)
{
var o = JObject.Parse(c.Result);
var videos = from v in o.Children() select new ydata { lyric = (string)v["lyric"], artist = (string)v["artist"], song = (string)v["song"], statusCod = (string)v["status"]};
lbLyric.ItemsSource = videos;
}
public class ydata
{
public string lyric { get; set; }
public string artist { get; set; }
public string song { get; set; }
public string statusCod { get; set; }
}
json:
{
"song":"Trust_In_Me",
"lyric":"How could I see You when I was so blind\u000aHow could I grasp You when I was far behind\u000aHow could I hear You when I was so deaf\u000aHow could I get up when I had been left\u000aBut You said don’t worry\u000aFor I’ve healed the blind man\u000aAnd I’ve set the captives free\u000aAnd You said don’t worry\u000aFor all you’ve gotta do\u000aIs put your trust in Me\u000aHow could I be clean when I was so dirty\u000aHow could I be made whole when I was torn apart\u000aMake me whole \u000aMake me whole\u000aMake me whole again\u000a",
"msgcode":"",
"status":"successful",
"artist":"Katy_Perry"
}
返回错误:Cannot access child value on Newtonsoft.Json.Linq.JProperty at line:
new ydata { lyric = (string)v["lyric"], artist = (string)v["artist"], song = (string)v["song"], statusCod = (string)v["status"]};
可能是因为我的 json 只有一个项目,因为它可以在其他有多个项目的 json 中工作。我该如何纠正这个问题?
【问题讨论】:
-
感谢您帮助我编辑问题。
标签: parsing windows-phone-7 json.net