0

I have large set of Json data returned from service. Now I want to convert this data to equivalent c# classes. Some Json data is related to metadata and some related to actual dataset. Json data is in flat hierarchy. I have tried JSON.Net as well but it converts the properties with same name. How i can convert the Json data in c# concrete classes ? I have draw a rough picture but just for the basic understanding (I am not much good in drawing :) )enter image description here

3
  • Create a new class with property exactly same as the json data, then you can easily deserialize and retrieve it Commented Aug 4, 2016 at 7:53
  • 1
    json.net comes with various attributes and options which should allow you to handle property name mapping and type conversion. This is pretty straightforward so I wonder what is the real point you are struggling with. Commented Aug 4, 2016 at 7:53
  • @Ehsan Hafeez refer this link I think it will help to you stackoverflow.com/questions/38607277/… Commented Aug 4, 2016 at 8:39

1 Answer 1

1

You say your JSON is actually a flat structure. Obviously JSON.NET has no notion of which properties belong to the actual days and which are metadata.

So let JSON.NET deserialize into the flat classes, and then map those classes into the nested classes that you want.

You can use AutoMapper for this.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.