Json数据转换list对象实现思路及代码
程序员文章站
2024-03-03 19:47:04
json代码: 复制代码 代码如下: [{"cid":2,"cname":"\u767d\u841d\u535c","amount":26,"price":"17"},{"...
json代码:
[{"cid":2,"cname":"\u767d\u841d\u535c","amount":26,"price":"17"},{"cid":3,"cname":"\u80e1\u841d\u535c","amount":21,"price":"21"},{"cid":4,"cname":"\u7389\u7c73","amount":7,"price":"23"},{"cid":14,"cname":"\u897f\u74dc","amount":7,"price":"29"},{"cid":5,"cname":"\u571f\u8c46","amount":3,"price":"24"},{"cid":1,"cname":"\u8349\u8393","amount":427,"price":"27"},{"cid":10,"cname":"\u5357\u74dc","amount":303,"price":"30"},{"cid":11,"cname":"\u82f9\u679c","amount":1,"price":"24"},{"cid":23,"cname":"\u77f3\u69b4","amount":4,"price":"54"},{"cid":18,"cname":"\u6843\u5b50","amount":3,"price":"40"},{"cid":15,"cname":"\u9999\u8549","amount":9,"price":"32"},{"cid":13,"cname":"\u8461\u8404","amount":7,"price":"47"},{"cid":26,"cname":"\u67da\u5b50","amount":1,"price":"58"},{"cid":27,"cname":"\u83e0\u841d","amount":5,"price":"62"},{"cid":19,"cname":"\u6a59\u5b50","amount":27,"price":"41"}]
vs2008
引用system.servicemodel.web.dll
引用system.runtime.serialization.dll
private void form1_load(object sender, eventargs e)
{
string _jsontext = system.io.file.readalltext(@"c:\2.txt");
list<test> _test = new list<test>();
datacontractjsonserializer _json = new datacontractjsonserializer(_test.gettype());
byte[] _using = system.text.encoding.utf8.getbytes(_jsontext);
system.io.memorystream _memorystream = new system.io.memorystream(_using);
_memorystream.position = 0;
_test =(list<test>)_json.readobject(_memorystream);
}
public class test
{
public int cid = 0;
public string cname = "";
public int amount = 0;
public string price = "";
}
复制代码 代码如下:
[{"cid":2,"cname":"\u767d\u841d\u535c","amount":26,"price":"17"},{"cid":3,"cname":"\u80e1\u841d\u535c","amount":21,"price":"21"},{"cid":4,"cname":"\u7389\u7c73","amount":7,"price":"23"},{"cid":14,"cname":"\u897f\u74dc","amount":7,"price":"29"},{"cid":5,"cname":"\u571f\u8c46","amount":3,"price":"24"},{"cid":1,"cname":"\u8349\u8393","amount":427,"price":"27"},{"cid":10,"cname":"\u5357\u74dc","amount":303,"price":"30"},{"cid":11,"cname":"\u82f9\u679c","amount":1,"price":"24"},{"cid":23,"cname":"\u77f3\u69b4","amount":4,"price":"54"},{"cid":18,"cname":"\u6843\u5b50","amount":3,"price":"40"},{"cid":15,"cname":"\u9999\u8549","amount":9,"price":"32"},{"cid":13,"cname":"\u8461\u8404","amount":7,"price":"47"},{"cid":26,"cname":"\u67da\u5b50","amount":1,"price":"58"},{"cid":27,"cname":"\u83e0\u841d","amount":5,"price":"62"},{"cid":19,"cname":"\u6a59\u5b50","amount":27,"price":"41"}]
vs2008
引用system.servicemodel.web.dll
引用system.runtime.serialization.dll
复制代码 代码如下:
private void form1_load(object sender, eventargs e)
{
string _jsontext = system.io.file.readalltext(@"c:\2.txt");
list<test> _test = new list<test>();
datacontractjsonserializer _json = new datacontractjsonserializer(_test.gettype());
byte[] _using = system.text.encoding.utf8.getbytes(_jsontext);
system.io.memorystream _memorystream = new system.io.memorystream(_using);
_memorystream.position = 0;
_test =(list<test>)_json.readobject(_memorystream);
}
public class test
{
public int cid = 0;
public string cname = "";
public int amount = 0;
public string price = "";
}
推荐阅读
-
Json数据转换list对象实现思路及代码
-
Json数据转换list对象实现思路及代码
-
ASP.NET中实现把Json数据转换为ADO.NET DataSet对象
-
将DataTable转换成List<T>实现思路及示例代码
-
ASP.NET中实现把Json数据转换为ADO.NET DataSet对象
-
将DataTable转换成List<T>实现思路及示例代码
-
php实现数组中索引关联数据转换成json对象的方法
-
php实现数组中索引关联数据转换成json对象的方法,数据转换json
-
php中操作json格式数据转换实现代码
-
使用谷歌Gson实现Json数据与Java对象、List、Map之间的相互转换笔记