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, где есть несколько элементов.Как я могу это исправить?