[asp.net] json数组、字符串 解析(转换为对象)

[asp.net] json数组解析(转换为对象)

引用 Newtonsoft.Json.dll


1、json字符串

string xxx = "{\"count\":\"1\",\"Product_Code\":\"14003949\",\"Product_Name\":\"聚丙烯树脂\",\"Product_Batch\":\"20140228D8103\",\"Certification_Code\":\"SCSH20140226-001-01\",\"Plate_Code\":\"L5E-89\",\"Grade\":\"合格品\",\"WarehouseIn_Num\":\"19120.0000000\",\"WarehouseIn_Weight\":\"478.000\",\"WarehouseIn_Confirm_Date\":\"2014-03-01\"}";


则直接转换为对象:


M_WarehouseInResult  whh = JsonConvert.DeserializeObject<M_WarehouseInResult>(xxx);


2、如果为json数组(注意:最外是中括号)


string xxx = "[{\"count\":\"1\",\"Product_Code\":\"14003949\",\"Product_Name\":\"聚丙烯树脂\",\"Product_Batch\":\"20140228D8103\",\"Certification_Code\":\"SCSH20140226-001-01\",\"Plate_Code\":\"L5E-89\",\"Grade\":\"合格品\",\"WarehouseIn_Num\":\"19120.0000000\",\"WarehouseIn_Weight\":\"478.000\",\"WarehouseIn_Confirm_Date\":\"2014-03-01\"}]";


json数组转换为list


List<M_WarehouseInResult> whh = JsonConvert.DeserializeObject<List<M_WarehouseInResult>>(xxx);




附:
    public class M_WarehouseInResult
    {
        public string count { get; set; }
        public string Product_Code { get; set; }




        public string Product_Name { get; set; }
        public string Product_Batch { get; set; }
        public string Certification_Code { get; set; }
        public string Plate_Code { get; set; }
        public string Grade { get; set; }
        public string WarehouseIn_Num { get; set; }
        public string WarehouseIn_Weight { get; set; }




        public string WarehouseIn_Confirm_Date { get; set; }
    }









  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值