简体   繁体   中英

c# class that maps per JSONs hierarchy

NOTE: This is NOT about serialization or deserialization of C# <==> JSON.

This is more about have a C# class that maps 1:1 onto JSON's structure itself. JSON can be either dictionaries (hashes) or arrays plus it can also be nested (eg: JSON objects as 'values' or array elements inside a JSON object). How can I define a C# class that behaves the same way such that it can map 1:1 onto it's JSON 'equivalent' ?

BTW, I do see that .NET 4.5 seems to have 1st class support for JSON (finally!) at http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspx . Plus it also seems to do serialization too. However that's a sealed class, so I can't see it's implementation.

Use the source Luke!

EDIT : It seems .NET 4.5 is open sourced. I found a link at http://referencesource.microsoft.com/netframework.aspx but can't seem to download the source. Tried 3 times with a corrupt download. Any other source location? It would be best to back-port the JSON class from .NET 4.5 => .NET 4.0

As long as you don't have any circular references in your class structure, you shouldn't have any issues with JSON mapping. But there are tools that can help minimize any ambiguity. Here's a relevant blog post that may help: http://bartwullems.blogspot.com/2012/06/json-to-c.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM