如何在C#中解析对象的JSON数组

问题描述:

{
   "jsonstring": [

  {
     "id":"01",
     "language": "Java",
     "edition": "third",
     "author": "Herbert Schildt"
  },

  {
     "id":"07",
     "language": "C++",
     "edition": "second",
     "author": "E.Balagurusamy"
  }


   ]
}

获取这样的发布请求如何解析此内容.

getting the post request like this how to parse this.

使用 NewtonSoft.NET :

var obj = JsonConvert.DeserializeObject(json);

也许也可以为使用泛型做一个相应的类:

Maybe make a corresponding class for using generics too:

public class ClassName {
    public string id { get; set; }
    public string language { get; set; }
    public string edition { get; set; }
    public string author { get; set; }
}

然后您可以做:

List<ClassName> list = JsonConvert.DeserializeObject<List<ClassName>>(json);