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"
}
它返回错误:无法访问Newtonsoft.Json.Linq.JProperty上的子值:
new ydata { lyric = (string)v["lyric"], artist = (string)v["artist"], song = (string)v["song"], statusCod = (string)v["status"]};
也许是因为我的json只有一个项目,因为它可以在其他有多个项目的json中工作。我怎么能纠正这个?
答案 0 :(得分:0)
结果很简单....这就是我所做的:
var o = JObject.Parse(c.Result);
txtLyric.Text = (string)o["lyric"];
lyricSongArtist.Text = "by " + (string)o["artist"];
lyricSongName.Text = (string)o["song"];
希望这有助于某人。