----------------------解析json到对象--------
string s = @"{'AA':'a','BB':'b','CC':{'DD':[{'name':'TOM','id':12},{'name':'JISON','id':23}],'EE':'E'}}";
Stream json_stream = new MemoryStream(System.Text.Encoding.Unicode.GetBytes(s));
DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(Class2));
Class2 chartJsData = (Class2)dataContractJsonSerializer.ReadObject(json_stream);
//MessageBox.Show(chartJsData.CC.DD[0]["name"].ToString());
---------实体-----
public class Class2
{
// string s = @"{'AA':'a','BB':'b','CC':{'DD':[{'name':'TOM','id':12},{'name':'JISON','id':23}],'EE':'E'}}";
public string AA { get; set; }
public string BB { get; set; }
public CC CC { get; set; }
}
public class CC
{
public string EE{get;set;}
public string[] DD { get; set; }
}
请问这里要怎么定义对象才可以接收到解析的对象? |