jToken与JArray简单笔记

jToken与JArray简单笔记

        //=============
        string outhtml = string.Empty;
        int error = HttpWebHelp.HttpHelp("http://s.music.163.com/search/get/?src=lofter&type=1&filterDj=true&s=千里之外&keywords&limit=30&offset=0", "get", null, null, null, ref outhtml);
        Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(outhtml);
        //方法一
        Newtonsoft.Json.Linq.JObject jObject1 = Newtonsoft.Json.Linq.JObject.Parse(jObject["result"].ToString());
        //Newtonsoft.Json.Linq.JArray jArray = Newtonsoft.Json.Linq.JArray.Parse(jObject.SelectToken("$.." + "songs").ToString());
        Newtonsoft.Json.Linq.JArray jArray = Newtonsoft.Json.Linq.JArray.Parse(jObject1.SelectToken("songs").ToString());
        Newtonsoft.Json.Linq.JObject jObject2 = Newtonsoft.Json.Linq.JObject.Parse(jArray[0].ToString());
        Console.WriteLine(jObject2["page"]);
        Console.WriteLine("================");
        foreach (Newtonsoft.Json.Linq.JToken item in jArray.Children())
        {
            Console.WriteLine(item["page"]);
            //Console.WriteLine(item.SelectToken("$.." + "page").ToString());
        }
        Console.WriteLine("================");
        //方法二
        Newtonsoft.Json.Linq.JToken jToken = jObject.SelectToken("$.." + "songs");
        foreach (Newtonsoft.Json.Linq.JToken item in jToken.Children())
        {
            //Console.WriteLine(item["page"]);
            Console.WriteLine(item.SelectToken("$.." + "page").ToString());
        }

        Console.ReadLine();

{
“result”: {
“songs”: [
{
“id”: 466332077,
“name”: “千里之外”,
“artists”: [
{
“id”: 166014,
“name”: “金志文”,
“picUrl”: null
},
{
“id”: 7159,
“name”: “白雪”,
“picUrl”: null
}
],
“album”: {
“id”: 35292021,
“name”: “厉害了!我的歌 第九期”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/utwtvnOvzxZiCxZPe-84sw==/19099616486134448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/466332077”
},
{
“id”: 28708828,
“name”: “千里之外的神秘解药”,
“artists”: [
{
“id”: 954540,
“name”: “金飞”,
“picUrl”: null
}
],
“album”: {
“id”: 2878520,
“name”: “传奇故事2014”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZ8bAX_sKMxeszKbIztDqg==/5882387208858864.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/28708828”
},
{
“id”: 455502557,
“name”: “一剪梅 + 千里之外 + 月圆花好”,
“artists”: [
{
“id”: 2747,
“name”: “费玉清”,
“picUrl”: null
}
],
“album”: {
“id”: 35139575,
“name”: “安徽卫视鸡年春晚现场原声专辑”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p2.music.126.net/EJM9i1GO7WIQAHepMT3kRQ==/18656513301855319.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/455502557”
},
{
“id”: 29783243,
“name”: “零点”,
“artists”: [
{
“id”: 1039038,
“name”: “Presto’C”,
“picUrl”: null
}
],
“album”: {
“id”: 3079037,
“name”: “流浪者的歌本创作选集”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/qssvJrFqe4BNOYPNV4sVXQ==/3238061745664688.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/29783243”
},
{
“id”: 84267,
“name”: “月满西楼”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84267”
},
{
“id”: 84285,
“name”: “十送红军”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84285”
},
{
“id”: 84294,
“name”: “牧羊曲”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84294”
},
{
“id”: 84302,
“name”: “美丽的草原我的家”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84302”
},
{
“id”: 84300,
“name”: “秋天不回来”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84300”
},
{
“id”: 84304,
“name”: “有谁共鸣”,
“artists”: [
{
“id”: 2774,
“name”: “方锐”,
“picUrl”: null
}
],
“album”: {
“id”: 8270,
“name”: “天弦千里之外”,
“artist”: {
“id”: 0,
“name”: “”,
“picUrl”: null
},
“picUrl”: “http://p1.music.126.net/CZfj5M_03ybiO6H-MXnLLg==/70368744190448.jpg”
},
“audio”: “”,
“djProgramId”: 0,
“page”: “http://music.163.com/m/song/84304”
}
],
“songCount”: 32
},
“code”: 200
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值