PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 23, 2022

[FIXED] How to deserialize a array with indexes that contains arrays in Newtonsoft.Json in c#

 July 23, 2022     c#, json     No comments   

Issue

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.


Solution

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...



Answered By - LivingOnTheRoad
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing