是否可以在 Windows 应用商店应用程序中使用本机DataContractJsonSerializer反序列化 json 数组?
示例,来自:
[{"groups":[{"name":"tom","vip":false},{"name":"sam","vip":true}]},{"groups":[{"name":"pam","vip":false},{"name":"mom","vip":true}]}]
到,大致在以下行中的任何内容:
public class Group
{
public string name { get; set; }
public bool vip { get; set; }
}
[DataContract]
public class RootObject
{
[DataMember]
public List<Group> groups { get; set; }
}
到目前为止,当我这样做时,我的尝试总是导致“空”列表或“空”IEnumerable:
public static T deserializeJson<T>(string result)
{
DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result)))
{
ms.Position = 0;
return (T)jsonSer.ReadObject(ms);
}
}