json字符串怎转换成json对象?
发布网友
发布时间:2022-04-20 21:59
我来回答
共1个回答
热心网友
时间:2023-11-06 16:12
下个Newtonsoft.Json插件\x0d\x0a引用 Newtonsoft.Json.dll\x0d\x0a\x0d\x0a1、json字符串\x0d\x0astring xxx = "{\"count\":\"1\",\"Proct_Code\":\"14003949\",\"Proct_Name\":\"聚丙烯树脂\",\"Proct_Batch\":\"20140228D8103\",\"Certification_Code\":\"SCSH20140226-001-01\",\"Plate_Code\":\"L5E-\",\"Grade\":\"合格品\",\"WarehouseIn_Num\":\"19120.0000000\",\"WarehouseIn_Weight\":\"478.000\",\"WarehouseIn_Confirm_Date\":\"2014-03-01\"}";\x0d\x0a\x0d\x0a则直接转换为对象:\x0d\x0a\x0d\x0aM_WarehouseInResult whh = JsonConvert.DeserializeObject(xxx);\x0d\x0a2、如果为json数组(注意:最外是中括号)\x0d\x0astring xxx = "[{\"count\":\"1\",\"Proct_Code\":\"14003949\",\"Proct_Name\":\"聚丙烯树脂\",\"Proct_Batch\":\"20140228D8103\",\"Certification_Code\":\"SCSH20140226-001-01\",\"Plate_Code\":\"L5E-\",\"Grade\":\"合格品\",\"WarehouseIn_Num\":\"19120.0000000\",\"WarehouseIn_Weight\":\"478.000\",\"WarehouseIn_Confirm_Date\":\"2014-03-01\"}]";\x0d\x0a\x0d\x0ajson数组转换为list\x0d\x0a\x0d\x0aListwhh = JsonConvert.DeserializeObject>(xxx);\x0d\x0a\x0d\x0a附:\x0d\x0a public class M_WarehouseInResult\x0d\x0a {\x0d\x0a public string count { get; set; }\x0d\x0a public string Proct_Code { get; set; }\x0d\x0a public string Proct_Name { get; set; }\x0d\x0a public string Proct_Batch { get; set; }\x0d\x0a public string Certification_Code { get; set; }\x0d\x0a public string Plate_Code { get; set; }\x0d\x0a public string Grade { get; set; }\x0d\x0a public string WarehouseIn_Num { get; set; }\x0d\x0a public string WarehouseIn_Weight { get; set; }\x0d\x0a public string WarehouseIn_Confirm_Date { get; set; }\x0d\x0a }