JSON代码:
复制代码 代码如下:
[{"cId":2,"cName":"u767du841du535c","amount":26,"price":"17"},{"cId":3,"cName":"u80e1u841du535c","amount":21,"price":"21"},{"cId":4,"cName":"u7389u7c73","amount":7,"price":"23"},{"cId":14,"cName":"u897fu74dc","amount":7,"price":"29"},{"cId":5,"cName":"u571fu8c46","amount":3,"price":"24"},{"cId":1,"cName":"u8349u8393","amount":427,"price":"27"},{"cId":10,"cName":"u5357u74dc","amount":303,"price":"30"},{"cId":11,"cName":"u82f9u679c","amount":1,"price":"24"},{"cId":23,"cName":"u77f3u69b4","amount":4,"price":"54"},{"cId":18,"cName":"u6843u5b50","amount":3,"price":"40"},{"cId":15,"cName":"u9999u8549","amount":9,"price":"32"},{"cId":13,"cName":"u8461u8404","amount":7,"price":"47"},{"cId":26,"cName":"u67dau5b50","amount":1,"price":"58"},{"cId":27,"cName":"u83e0u841d","amount":5,"price":"62"},{"cId":19,"cName":"u6a59u5b50","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 = "";
}