我想从json响应中的数组中获取数据。 这是json:
{
"program":{
"title":"show",
"image_url":"NOA_17.jpg"
},
"noa":[
{
"title":"Title1",
"artist":"Artist1",
},
{
"title":"Title2",
"artist":"Artist2",
}
]
}
我想获得Title1& Artist1在那里。
我希望有人可以帮助我。
提前谢谢。
答案 0 :(得分:2)
修复
"artist":"Artist1",
"artist":"Artist2",
到
"artist":"Artist1"
"artist":"Artist2"
E.g。
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"]);
}
}