Serialization.Json反序列化時數據值為空
廣告:
Serialization.Json反序列化時數據值為空
using System.Runtime.Serialization.Json;
原因一是:json數據格式不對 : Json數據跟類名一一對應,區分大小寫
應為以下格式:
[ { "Areaid": "1", "Cnname": "北京市", "Total": "118" },{ "Areaid": "20", "Cnname": "上海市", "Total": "37"}]
二是:數據約定[DataContract]:
using System.Runtime.Serialization;
[DataContract]
public class Province
{
[DataMember]
public int Areaid { get; set; }
[DataMember]
public string Cnname { get; set; }
[DataMember]
public int Total { get; set; }
[DataMember]
public string Childclass { get; set; }
[DataMember]
public List<Province> ProvinceItems { get; set; }
}
成功顯示:
List<Province> list = JsonHelper.JsonDeserialize<List<Province>>(jsonString);
foreach (Province m in list)
{}
廣告: