Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Convert Class Object to JSON string?

Im using C#, ASP.NET v1.1. My class contains intrinsic types, ArrayList, and XmlDocument types. Some variables have the value NULL.

After usng XmlSerializer and the information on: http://www.phdcc.com/xml2json.htm I'm having issue fully converitng my class object to a javascript readable string.

The XmlSerializer appears to ignore all variables containing NULL and so the final JSON output is incomplete. Also I have a DateTime object within my class. The converted date is horrible, certainly not even close to what Javascript can parse. Is there a way to set the datetime format.

Is there anything i can do to resolve this or a better tool for converting my class object to JSON string?
[730 byte] By [quantass] at [2007-11-11 10:11:34]
# 1 Re: Convert Class Object to JSON string?
It looks like Microsoft's ASP.NET (2.0) AJAX Extensions support XML-to-JSON serialization. With ASP.NET 1.1, you may need to create a custom serializer to get the behavior you desire. For more information on custom serialization, see http://www.15seconds.com/issue/020903.htm
Phil Weber at 2007-11-11 23:12:00 >