Deserializing JSON with unknown object names

后端 未结 1 1977
伪装坚强ぢ
伪装坚强ぢ 2020-12-04 02:30

I\'m trying to deserialize a JSON response from an API. The JSON looks like this (MAC addresses and location are altered):

{
\"body\" : [{
        \"_id\" :          


        
相关标签:
1条回答
  • 2020-12-04 03:10

    It looks like you should be able to just get rid of your Measures class. Instead, put the dictionary straight into your Body class:

    public class Body
    {
        public string _id { get; set; }
        public Place place { get; set; }
        public int mark { get; set; }
        public Dictionary<string, SingleModule> measures { get; set; }
        public string[] modules { get; set; }
    }
    

    As a separate matter, I'd strongly recommend following .NET naming conventions for your properties, and using [JsonProperty("measures")] etc to indicate to Json.NET how to translate your properties into JSON.

    0 讨论(0)
提交回复
热议问题