对前台传的json进行解析

#region JavaScriptSerializer

//这是一种C#自带的序列化的方式
//JavaScriptSerializer Serializer = new JavaScriptSerializer();
//List<Product> objs = Serializer.Deserialize<List<Product>>(name);
#endregion

#region JsonConvert

//使用第三方
//List<Product> jobInfoList = JsonConvert.DeserializeObject<List<Product>>(name);
#endregion

//用数组来接受 然后把数组转成对象
JArray javascript = (JArray)JsonConvert.DeserializeObject(name);
List<string> list = new List<string>();
for (int i = 0; i < javascript.Count; i++)
{
JObject obj = (JObject)javascript[i];
string outValue = obj["Name"].ToString(); //将一个个反序列化的JSON字符串数组转换成对象
list.Add(outValue);
}

 

 

  1. public static List<T> JSONStringToList<T>(this string JsonStr)  
  2. {  
  3.     JavaScriptSerializer Serializer = new JavaScriptSerializer();  
  4.     List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);  
  5.     return objs;  
  6. }  
posted @ 2016-05-30 23:42  Jesh_95  阅读(968)  评论(0编辑  收藏  举报