C#中将json转化成list

在程序集中添加引用 System.Web.Extensions

在类中添加引用

using System.Runtime.Serialization;
using System.Web.Script.Serialization;

{"Total":"0",
"Rows":
[
{
"id":"31",
"project":"6",
"project_name":"测试",
"name":"哈哈!",
"assignedTo":"liming",
"realname":"李明",
"estStarted":"2016/11/23",
"realStarted":"2000/01/01",
"status":"wait"
},
{
"id":"32",
"project":"6",
"project_name":"嘻嘻",
"name":"你好",
"assignedTo":"wangwu",
"realname":"王五",
"estStarted":"2016/11/23",
"realStarted":"2016/11/23",
"status":"wait"
}
]}

int IndexofA = jsonText.IndexOf("[");
int IndexofB = jsonText.IndexOf("]");
string Ru = jsonText.Substring(IndexofA , IndexofB - IndexofA+1);

JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<Test> objs = Serializer.Deserialize<List<Test>>(Ru);

//实体类

 public class Test
        {
            public int id { get; set; }
            public string project { get; set; }
            public string project_name { get; set; }
            public string name { get; set; }
            public string assignedTo { get; set; }
            public string realname{ get; set; }
            public string estStarted { get; set; }
            public string realStarted { get; set; }
            public string status { get; set; }
        }
 

猜你喜欢

转载自blog.csdn.net/feelsyt/article/details/89426937