代码如下
class Results
{
public auction result { get; set; }
}
class auction
{
public List<auctiondetail> auctions { get; set; }
}
class auctiondetail { public string category{ get; set; } public string userType{ get; set; } public string biz30Day { get; set; }// 销量:1758 } private void test() { string json={"result":{"auction":[{"biz30Day":35,"category":50010850,"userType":0},{"biz30Day":23,"category":50010850,"userType":0}]},"resultCode":0,"success":true};
Results result = new Results();
result = new JavaScriptSerializer().Deserialize<Results>(json);
if (result.result.auctions == null)
{
}
foreach (auctiondetail item in result.result.auctions)
{
}
}
JSON中字段名为auction 实体类中字段名为auctions
一楼说的对。
Json字符串中的值的名称和实体中对应字段的名称不一致,一楼正解!
一楼正解