开发者

parse json windows phone 7 cann't access child error

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 stri开发者_开发百科ng 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"
}

it return the error: 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"]};

Maybe because my json only has one item, because it work in other json where there is multiple item. How can I correct this?


it turn out quite simple.... here is what I did:

        var o = JObject.Parse(c.Result);
            txtLyric.Text = (string)o["lyric"];
            lyricSongArtist.Text = "by " + (string)o["artist"];
            lyricSongName.Text = (string)o["song"];

Hope this help someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜