-2

I've a json that have objects like this

"SeasonalInfoBySeasonID": {  
"aa8e0d2d-d29d-4c03-84f0-b0bda96a9fe1": {
                "ID": "aa8e0d2d-d29d-4c03-84f0-b0bda96a9fe1",
                "A": "1",
                "B": 5,
            },
"6f95fb92-5eb2-4fe4-ae01-dc54d810c8a5": {
                "ID": "6f95fb92-5eb2-4fe4-ae01-dc54d810c8a5",
                "A": "1",
                "B": 5,
            }, .....
}

the objects of SeasonalInfoBySeasonID are clearly all of the same data structure, but unfortunately they aren't even listed in an array, and instead of listing them one by one in seasoninfobyseasonid model I'm using doing this:

public class SeasonalInfoBySeasonID
    {
        private IDictionary<string, object> _additionalProperties = new Dictionary<string, object>();

        [JsonExtensionData]
        public IDictionary<string, object> AdditionalProperties
        {
            get { return _additionalProperties; }
            set { _additionalProperties = value; }
        }
    }

works great, but I was wondering is it possible to de-serialize such an object with multiple objects of the "same type", to an array directly?

Dartz
  • 11
  • 4
  • *nested - Embedded, Successively fitted one inside another.* ... there is no nesting in your json - where is example? ... also you can always use custom converter to do whatever you want – Selvin May 24 '22 at 07:45
  • Declare the original property `public Dictionary SeasonalInfoBySeasonID {get;set;} = new();` and remove the class `SeasonalInfoBySeasonID` altogether. See for example https://stackoverflow.com/questions/70066572/deserialize-json-to-object-with-a-dictionary-system-text-json – Charlieface May 24 '22 at 08:46
  • @Charlieface please post your comment as an answer, to mark it – Dartz May 24 '22 at 10:10

1 Answers1

0

You don't need the class at all.

You can just declare the property on the root object like this

public Dictionary <string, YourType> SeasonalInfoBySeasonID {get;set;} = new Dictionary <string, YourType>();

Then each key will be aa8e0d2d-d29d-4c03-84f0-b0bda96a9fe1 etc., and the objects will be the inner type.

Charlieface
  • 52,284
  • 6
  • 19
  • 43