Newtonsoft JSON.NET parse to array of custom key/value pair objects

后端 未结 2 609
春和景丽
春和景丽 2020-12-22 03:31

I have this strange issue with parsing given JSON data. I have this JSON structure:

{\"value\":[
  {\"street\":\"Karlova 25\"},
  {\"city\":\"Prague\"},
  {\         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-22 04:01

    You don't need to reinvent the wheel. This funcionality is already working. Create classes like below:

    public class Value
    {
        public string street { get; set; }
        public string city { get; set; }
        public string gpsLat { get; set; }
        public string gpsLon { get; set; }
    }
    
    public class MyClass
    {
        public List value { get; set; }
    }
    

    Now You can simply deserialize your json to your poco object.

    MyClass result  = JsonConvert.DeserializeObject(youJson);
    

提交回复
热议问题