C# json解析
json={
"employees":[
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName": "Carter" }
]
}
"employees":[
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName": "Carter" }
]
}
解析上面的json:
第一步:在程序集里面添加 using Newtonsoft.Json.Linq;
第二步:开始解析:
Jobject jo=json.Value<Jobject>("employees");
JArray jar=JArray.Parse(json["employees"].ToString()); //解析带数组的json
for(int i=0;i<jar.count;i++)
{
JObject jo = JObject.Parse(jar[i].ToString());
string strFirstName=jo.Value<string>("firstName").Trim();
string strLastName=jo.Value<string>("lastName").Trim();
}