Json数据转换list对象实现思路及代码
网络编程 2021-07-04 22:40www.168986.cn编程入门
本文为大家详细介绍下Json数据转换list对象的具体实现,感兴趣的朋友可以参考下哈,希望对你有所帮助
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 = "";
}
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程