C# 中将json字符串转化成List
程序员文章站
2022-06-16 10:32:15
...
在程序集中添加引用 System.Web.Extensions
在类中添加引用
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<DropDownBasicData> mouldNameList = Serializer.Deserialize<List<DropDownBasicData>>(GetMouldName().ToString());
//kendo select的數據源格式
public class DropDownBasicData
{
public string DropDownId { get; set; }
public string DropDownValue { get; set; }
public string DropDownText { get; set; }
}
//序列化:List 转 json字符串
Newtonsoft.Json.JsonConvert.SerializeObject(result);
//反序列化:json字符串 转 List
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<DropDownBasicData> mouldNameList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DropDownBasicData>>(GetMouldNameToStr());
上一篇: WIN32创建居中对话框
下一篇: js学习笔记(一)变量