I've been looking into several JSON parsers for .NET (LitJSON, JsonExSerializer and JSON.NET), and was wondering if anyone has any experience with them and can shed some light on the differences and the pros and cons for each of them.
Don't forget, .NET 3.5 introduced the JavaScriptSerializer class which does JSON as well. I haven't used the others because I've always just used the built-in one: it works well enough for everything I've needed.
Since this thread seems to attract very little attention, here's what I ended up doing: liJson was out of the picture pretty fast as it does not seem to be actively maintained. Between the remaining two (both released versions just a few days ago) I chose Json.NET as it seems to
- have a slightly simpler serialization API.
- be more popular.
After a few experiments I have to say I'm happy with the results - I managed to achieve all I wanted and more, and writing custom converters was a breeze, taking 2 minutes and 4 lines of code.
JavaScriptSerializer has some major shortcomings out of the box, but with a bit of cajoling it can be convinced to do some neat stuff, like deserializing d: wrapped msajax json and typed wcf json as well as deserializing to anonymous types.
See http://www.codeproject.com/KB/aspnet/Parsing-ClientScript-JSON.aspx
If you're using MVC3, check out Json.Decode() (native method included with MVC as a helper) which can return a 'dynamic' object.
So you can quickly just call:
dynamic result = Json.Decode(jsonData);
And access it like result.theProperty.
Check out kiwi.json https://github.com/jlarsson/Kiwi.Json It looks very promising and is lightning fast as far as I've experienced.
精彩评论