json字符串转对象

蹦跶的皮蛋 2016-02-20 06:33:04
{
"status": {
"status_code": 0,
"status_reason": ""
},
"result": {
"items": [
{
"itemID": "1669769210",
"itemName": "LG香水身体乳",
"itemKdName": "LG香水身体乳",
"itemKdDesc": "",
"src_img": "http://wd.geilicdn.com/vshop843060031-1449386900964-36588-s1.jpg?w=480&h=0",
"img": "http://wd.geilicdn.com/vshop843060031-1449386900964-36588-s1.jpg?w=267&h=267&cp=1",
"price": "53.00",
"h5url": "http://weidian.com/i/1669769210",
"stock": "300",
"isTop": 0,
"sold": "0",
"edittime": "12-23",
"addtime": "12-06",
"add_time": "2015-12-06 15:28:21",
"update_time": "2015-12-23 16:04:25",
"e_time": 1450857865,
"a_time": 1449386901,
"fx_fee_rate": "",
"is_distributor": 0,
"hasPrice": 1,
"sku": {},
"is_seckill": 0,
"discount": 0,
"priceKill": "0",
"startTime": "",
"endTime": "",
"isEditorChoice": 0,
"cates": [
{
"cate_id": "64128198",
"cate_name": "洗漱用品",
"sort_num": "30"
},
{
"cate_id": "64128927",
"cate_name": "化妆品",
"sort_num": "50"
}
],
"collectCount": 0,
"item_collect_count": 0
}
],
"offset": {
"wd_offset": 1,
"fx_offset": 0
}
}
}

上面这个是获取到json字符串

#region 类----对应获取到json数据的键
public class data
{
public status status { get; set; }
public result result { get; set; }
}
public class result
{
public List<items> items1 { get; set; }
public offset offset { get; set; }
}
public class status
{
public string status_code { get; set; }
public string status_reason { get; set; }
}

public class items
{
public string itemID { get; set; }
public string itemName { get; set; }
public string itemKdName { get; set; }
public string itemKdDesc { get; set; }
public string src_img { get; set; }
public string img { get; set; }
public string price { get; set; }
public string h5url { get; set; }
public string stock { get; set; }
public string isTop { get; set; }
public string sold { get; set; }
public string edittime { get; set; }
public string addtime { get; set; }
public string add_time { get; set; }
public string update_time { get; set; }
public string e_time { get; set; }
public string a_time { get; set; }
public string fx_fee_rate { get; set; }
public string is_distributor { get; set; }
public string hasPrice { get; set; }
public sku sku { get; set; }
public string is_seckill { get; set; }
public string discount { get; set; }
public string priceKill { get; set; }
public string startTime { get; set; }
public string endTime { get; set; }
public string isEditorChoice { get; set; }
public List<cates> cates1 { get; set; }
public string collectCount { get; set; }
public string item_collect_count { get; set; }
}
public class sku
{

}
public class cates
{
public string cate_id { get; set; }
public string cate_name { get; set; }
public string sort_num { get; set; }
}
public class offset
{
public string wd_offset { get; set; }
public string fx_offset { get; set; }
}
#endregion

定义的
 JavaScriptSerializer js = new JavaScriptSerializer();
data sn = js.Deserialize<data>(jsonstring);

这样怎么获取不到“items”里面的内容呢
显示null
在线等 急!
...全文
198 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxl_88 2016-02-24
  • 打赏
  • 举报
回复
用Newtonsoft.Json
秋的红果实 2016-02-23
  • 打赏
  • 举报
回复
你用断点检查下,程序可以正确走到哪里?要不,这么多代码,不好确定
  • 打赏
  • 举报
回复
你把字段名写错了,多写了一个字母“1”。
letianpai688 2016-02-23
  • 打赏
  • 举报
回复
类型定义错误
software_artisan 2016-02-20
  • 打赏
  • 举报
回复
目测类型定义错误
qbilbo 2016-02-20
  • 打赏
  • 举报
回复
目测了一下,发现几个集合定义的不对。 public List<items> items1 { get; set; }改成public List<item> items { get; set; },对应的public class items改成public class item public List<cates> cates1 { get; set; }改成public List<cate> cates { get; set; },对应的public class cates改成public class cate 另外,那些值没有被引号引起来的不要定义成string,定义成int或long什么的。
  • 打赏
  • 举报
回复
http://blog.csdn.net/starfd/article/details/48686239 先按这个确认json对应的类是否正确,然后如果可以,用Newtonsoft.Json

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧