2

I have some JSON here. The problem is it doesn't match the classes data types anymore. My question is; is it possible to deserialize JSON Dynamically? i.e. if I have entirely different JSON's can I deserialize them into two entirely different classes without first knowing what class I want to deserialize each into.

d219
  • 2,707
  • 5
  • 31
  • 36

1 Answers1

8

You can deserialize dynamic object with using newtonsoft

like bellowing code piece.

 dynamic dynamicObj = JsonConvert.DeserializeObject(jsonStr);
 string name = dynamicObj.data.code;

But in my personal preference is using strong type. I think its more convenience.

you can use quictype for generating c# classes from JSON object

quicktype generates strongly-typed models and serializers from JSON, JSON Schema, and GraphQL queries, making it a breeze to work with JSON type-safely in any programming language.

Hope the answer helps to you.

arslanaybars
  • 1,813
  • 2
  • 24
  • 29