0

I have the following Json string returned from an API:

{
"1":{"key":"value", "key2":"value2"},
"2":{"key":"value", "key2":"value2"},
"3":{"key":"value", "key2":"value2"}
}

The numbering can go up to move than 10.000.

I use Json.Net for deserializing. Usually I declare a class with the properties key and key2 and make it a list. Then i deserialize with JsonConvert.Deserialize(...) and it works fine.

But how do I handle the numbering? I cannot create > 10.000 properties to hold the values.

Best regards Morten

MortenGR
  • 803
  • 1
  • 8
  • 22
  • Even if marked as duplicate, the other answer was really difficult to find. I think I will leave this question here with a reference to the other question. The problem domain for the two questions also differs: Illegal identifies versus correct property structure for deserialization. – MortenGR Aug 11 '15 at 13:31

1 Answers1

1

You can use Dictionary to deserialize your json

var obj = JsonConvert.DeserializeObject<Dictionary<int, AClass>>(JsonConvert);


public class AClass
{
    public string key { set; get; }
    public string key2 { set; get; }
}
Eser
  • 12,346
  • 1
  • 22
  • 32