In The craft
Using JSON Serialization over XML Serialization
I like JSON. It’s simple, key-value pairs embodied in minimal metadata.
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
The beauty is in its expressiveness and terseness.
In .Net JSON can be used to serialize and Deserialize objects.
protected T Serialize(string val)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Deserialize(val);
}
Why would anyone use XML serialization when the same can be achieved with JSON? JSON only stores the key-value pairs. Metadata about the origins of the data do not exist. This means as long as the keys are the same on the destination object and the values are of compatible type, it will just work.