0

I have to parse JSON of an external API and struggle to convert it into a strongly-typed C# object. Already checked NewtonSoft Json parse examples into dynamic type, but I guess none of them suits my need. To make it clear, the ids (1, 3, 4, and 227) are dynamically generated. I would appreciate any help.

{
  "brands":{
     "any":false,
     "1":{
        "is_all":true
     },
     "3":{
        "is_all":true
     },
     "4":{
        "is_all":true
     },
     "227":{
        "is_all":false,
        "values":[
           3931
        ],
        "include":true
     }
  },
  "color":[
     1,
     2,
     3
  ],
  "gearbox_id":[
     2
  ]
}
Farhad Mammadli
  • 469
  • 1
  • 5
  • 15
  • [Does this answer your question?](https://stackoverflow.com/questions/24771804/how-can-i-deserialize-a-child-object-with-dynamic-numeric-key-names). I would describing in detail the problem you are having as I can only guess that it's the varying key names that you're stuck on. – ProgrammingLlama Mar 18 '20 at 09:57
  • It is similar but does not fit. The problem is that the dynamically created ids do not have the same properties... – Farhad Mammadli Mar 18 '20 at 10:00
  • It really depends on if you have a fixed schema. If yes, you could try deserialize `brands` into a dictionary. If no fixed schema, `dynamic` might be cleaner way. – weichch Mar 18 '20 at 10:08
  • 1
    The main issue are not the property of Brand object but the `"any":false,`.. You may need a custom parser for that. – Drag and Drop Mar 18 '20 at 12:47
  • Yeah, that is the main issue, could not resolve it yet – Farhad Mammadli Mar 20 '20 at 15:33

0 Answers0