Is there a built in way in .Net AJAX to manually serialize an object to a JSON string?
ScriptingJsonSerializationSection but I'm not sure how to use it. I could write a function to convert the object to a JSON string manually, but since .Net can do it on the fly with the
<System.Web.Script.Services.ScriptMethod()> attributes so there must be a built-in way that I'm missing.
PS: using Asp.Net 2.0 and VB.Net - I put this in the tags but I think people missed it.
6 answers given for "Is there a built in way in .Net AJAX to manually serialize an object to a JSON string?"
This should do the trick
I think what you're looking for is this class:
Here's an example from Rick Strahl: DataContractJsonSerializer in .NET 3.5
Well, I am currently using the following extension methods to serialize and deserialize objects:
I use this quite a bit - be forewarned, this implementation is a bit naive (i.e. there are some potential problems with it, depending on what you are serializing and how you use it on the client, particularly with DateTimes).
or Check out JSON.org there is a whole list of libraries written to do exactly what you want.