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 :) )
Asked
Active
Viewed 404 times
0

Ehsan Hafeez
- 648
- 6
- 24
-
Create a new class with property exactly same as the json data, then you can easily deserialize and retrieve it – jonju Aug 04 '16 at 07:53
-
1json.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. – Cyprien Autexier Aug 04 '16 at 07:53
-
@Ehsan Hafeez refer this link I think it will help to you http://stackoverflow.com/questions/38607277/how-to-parse-an-example-string-in-c-sharp/38608187#38608187 – Shakir Ahamed Aug 04 '16 at 08:39
1 Answers
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.

CodeCaster
- 147,647
- 23
- 218
- 272