Json怎么解析下面的数据?
{
"details": [
{
"A": [
[
"老王",
"60岁"
],
[
"老李",
"72岁"
]
],
"DataTime": 1389542400000,
"B": [
0,
289277,
61086
],
"C": [
26567,
27263
],
"D": false
},
]
}
using Newtonsoft.Json;
string jj="{"details": [{"A": [["老王","60岁"],["老李","72岁"]],"DataTime": 1389542400000,"B": [0,289277,61086],"C": [26567,27263],"D": false},]}";
string js = GetJsonContent(jj);
JArray jsonval = JArray.Parse(js) as JArray;
dynamic al = jsonval;
foreach (JObject aa in al)
{
string a1= aa["A"][0].ToString();
string a2 = aa["A"][1].ToString();
string dt = aa["DataTime"].ToString();
string b1 = aa["B"][0].ToString();
string b2 = aa["B"][1].ToString();
string b3 = aa["B"][2].ToString();
string c1 = aa["C"][0].ToString();
string c2= aa["C"][1].ToString();
string d = aa["D"].ToString();
}
private String GetJsonContent(String QueryResult)
{
string pattern = "{"details":(.*)}";
var result = Regex.Match(QueryResult, pattern, RegexOptions.IgnoreCase).Groups;
if (result.Count > 1)
{
return result[1].Value;
}
return string.Empty;
}
private void Test()
{
string str = @"......";
JsonClass1 ce = FromJson<JsonClass1>(str);
}
public T FromJson<T>(string json)
{
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
DataContractJsonSerializer j = new DataContractJsonSerializer(typeof(T));
return (T)j.ReadObject(ms);
}
public class JsonClass1
{
public JsonClass2[] details;
}
public class JsonClass2
{
public string[][] A;
public long DataTime;
public int[] B;
public int[] C;
public bool D;
}