对前台传的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);
}
- public static List<T> JSONStringToList<T>(this string JsonStr)
- {
- JavaScriptSerializer Serializer = new JavaScriptSerializer();
- List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);
- return objs;
- }