I have all this JSON text that I want to deserialize (or something) into an object with variables so I can run through it and add/change some things and then serialize it back to text. Is there something built in from Microsoft for this?
views:
86answers:
4If you were using MVC, there are JSON methods, for output, but it is also possible to use action filters to deserialise json that is passed in. There are some quirks to this but it does work well with json submitted via jQuery etc.
WCF has the DataContractJsonSerializer
but I haven't used it myself - I've always gone for Json.NET which I've found to be broadly excellent.
I'd expect the WCF serializer to be a good fit if you're using WCF, but if you're writing a standalone app, I'd go for Json.NET. It's a pretty straightforward dependency. In particular, I like the fact that I don't actually have to model the classes directly in order to use Json.NET - I tend to use the "LINQ" side of the library which is a little like LINQ to XML, but applied to JSON. I deal directly in JArray
, JObject
, JToken
etc and let Json.NET just do the parsing/formatting.
The fancy new "AJAX" stuff come with JavaScriptSerializer (built into Framework 3.5 and later, at least) It's not quite as flexible as, say, the XML serializers but it does the job in many cases.
I believe there are some built in, but I don't think they are terribly powerful by themselves. We have always used this library. It's very powerful and easy to use.
It's fantastic for serializing objects and lists or deserializing JSON.