当前位置: 首页 > 工具软件 > jtoken > 使用案例 >

jToken与JArray简单笔记

谢灵均
2023-12-01

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
}

 类似资料: