How to parse a JSON array of objects in C#

后端 未结 2 1182
失恋的感觉
失恋的感觉 2020-12-22 14:11
{
   \"jsonstring\": [

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

  {
     \"id\":         


        
2条回答
  •  清歌不尽
    2020-12-22 14:46

    Use 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; }
    }
    

    then you can do:

    List list = JsonConvert.DeserializeObject>(json);
    

提交回复
热议问题