Home > Software design >  How to deserialize a array with indexes that contains arrays in Newtonsoft.Json in c#
How to deserialize a array with indexes that contains arrays in Newtonsoft.Json in c#

Time:07-23

I have an API that returns a JSON of this structure:

{
   "1":[
      {
         "name":"One"
      },
      {
         "name":"Two"
      }
   ],
   "2":[
      {
         "name":"Three"
      }
   ]
}

I need to deserialize it in C# using Newtonsoft.Json. I have tried deserializing in a List<List<Response>> but it didn't work.

I understand that the JSON is not necessarily good, but I can't change it since it's on a third party server.

Every help is appreciated.

CodePudding user response:

Deserialize into a dictionary (or SortedDictionary, if the order of the elements in the dictionary matter), then take the dictionary's Values collection and run...

  • Related