Deserialize JSON with dynamic objects

后端 未结 4 946
梦毁少年i
梦毁少年i 2020-12-11 02:41

I have a JSON object that comes with a long list of area codes. Unfortunately each area code is the object name on a list in the Data object. How do I create a class that wi

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 03:01

    I think using Dictionary is the easiest way.

    public class phaxioResponse
        {
            public string success { get; set; }
            public string message { get; set; }
            public Dictionary data { get; set; }
    
            public class areaCode
            {
                public string city { get; set; }
                public string state { get; set; }
            }
        }
    

    Then:

        var res= JsonConvert.DeserializeObject(json);
        Console.WriteLine(string.Join(",", res.data));
    

提交回复
热议问题