C# – Serialization and Deserialization of JSON

Whatever they tell you C# is somehow a fancy language. One of the reasons for this is that you may use the hard work of plenty of other good developers for free and without even thinking of how to make your own libraries for trivial stuff.

E.g., if you have some input data, coming as a JSON, which should be taken from your application, edited and returned as a JSON, C# can process the whole action with the assistance of the using System.Web.Script.Serialization; magic library.

So, lets say we work in a shop for tables and we obtain the following JSON:

string strXML = @”{“”ObjectType”” : “”Table””, “”Price”” : 512, “”Shops”” : [“”IKEA””,””VityataShop””]}”;

Not exactly JSON, but you get the idea 🙂 C# and the Web.Script library helps us to make an Object out of it and to edit it there. Then we may change data in the object (of course!) and export the JSON back. Nice and shiny.

Like this:

Here is the console:

pic2

Enjoy it! 🙂

About

VBA Developer

Tagged with: , ,