///
/// JSON格式数组转化为对应的List
///
///
/// JSON格式数组
///
public static ListJSONStringToList (string JsonStr)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
//设置转化JSON格式时字段长度
Listobjs = Serializer.Deserialize >(JsonStr);
return objs;
}
//调用方法
ListTD_Share = new List ();
TD_Share = JSONStringToList(JsonStr);
你构造一个类 里面有carLengthMin等3个成员
我这里是DBTD_SHARE
public class Model
{
public int Count { set; get; }
public List Data { set; get; }
}
public class Data
{
public string carLengthWin { set; get; }
public string carAxleRequire { set; get; }
public string tradeTelephoneNumber { set; get; }
}
然后使用JavaScriptSerializer的Deserialize方法反序列化,参数是json
var json=new JavaScriptSerializer().Deserialize(jsonString);
如果这里没有对映的实体类,那么这里的T可以用Dictionary和dynamic代替。。哪种是用看你自己
引用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
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
}
public class Test
{
public int cId = 0;
public string cName = "";
public int amount = 0;
public string price = "";
}
你根据你自给的东西修改下吧
你得构造一个和这个Json结构一样的类。
然后用JavaScriptSerializer类的Deserialize方法反序列化。