从json中获取数组
本文关键字:数组 获取 json | 更新日期: 2023-09-27 18:18:11
我想从json响应的数组中获取数据。这是json:
{
"program":{
"title":"show",
"image_url":"NOA_17.jpg"
},
"noa":[
{
"title":"Title1",
"artist":"Artist1",
},
{
"title":"Title2",
"artist":"Artist2",
}
]
}
我想要得到Title1 &艺术家离开这里。
我希望有人能帮我做这件事。
提前感谢。
fix
"artist":"Artist1",
"artist":"Artist2",
"artist":"Artist1"
"artist":"Artist2"
。
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web.Script.Serialization;
class Sample {
static void Main(){
string json = File.ReadAllText("json.txt");
var jss = new JavaScriptSerializer();
var dic = jss.Deserialize<Dictionary<string, object>>(json);
var noa = (ArrayList)dic["noa"];
var noa_1 = (Dictionary<string, object>)noa[0];
Console.WriteLine("title is {0}",noa_1["title"]);
Console.WriteLine("artist is {0}",noa_1["artist"]);
}
}