views:

86

answers:

4

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?

+3  A: 

If 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.

Check this out

Mark Dickinson
ah I am using MVC, thanks for the link
shogun
+6  A: 

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.

Jon Skeet
Thats cool too, you can get WCF endpoints to deserialize JSON, even called from Microsoft AJAX. It's a million miles from what I'm doing now, but you can get it working in an afternoon easy :)
Mark Dickinson
A: 

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.

Matti Virkkunen
A: 

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.

http://json.codeplex.com/

jocull