这是我的JSON的结构:
string sample =
"[{'Disp_Name':'avi garg',
'emailId':'avi@india.com',
'fName':'avi',
'lName':'garg',
'ph':{'number':'9813612344(Mobile)','type':1}
},
{'Disp_Name':'monk gup',
'emailId':'mon@india.com',
'fName':'monk',
'lName':'gup',
'ph':{'number':'01127243480(home)','type':2}
}]";
我想将它反序列化回我班级的对象数组。有人可以帮我解决这个问题吗?我想最好使用datacontractjsonserializer,但其他人也很好。
感谢你
答案 0 :(得分:1)
public static List<your class> decrypt_json(string json)
{
var deserializedUser = new List<your class>();
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
DataContractJsonSerializer ser=new DataContractJsonSerializer(deserializedUser.GetType());
deserializedUser = ser.ReadObject(ms) as List<your class>;
MessageBox.Show(deserializedUser.Count().ToString());
ms.Close();
return deserializedUser;
}