Im using ASP.NET C# (framework v1.1) under Windows 2003. I'm trying to
serialize my class object to return as JSON to my awaiting Javascript code, then take in JSON
from the client side and convert it back to my C# object. I've tried using
XmlSerializer, AjaxPro .Net, and some misc code but everything has problems;
XmlSerializer refuses to serialize my class because it contains an ArrayList
that stores a different class type:
public class MyClass
{
int
a=1;
ArrayList b = new ArrayList();
XmlDocument xml;
}
public class
MySection
{
int x=1;
}
MyClass mClass = new
MyClass();
mClass.b.Add(new MySection());
XmlSerializer serializer =
new XmlSerializer(typeof(MyClass));
StringWriter sw = new
StringWriter();
serializer.Serialize(sw, mClass);
sw.Close();
Eventually when i try to serialize mClass to a string I receive a
useless error:
An unhandled exception of type 'System.InvalidOperationException'
occurred in system.xml.dll
Additional information: There was an error
generating the XML document.
AjaxPro.NET has a nice Serializer to string
but it is completely clueless when it comes to XmlDocument, a member of my
class.
One person has recommended Ajax.NET but I havent read up on it and dont want to go down yet another dead end. Is there a library for C# that can fully convert a class object
(regeardless of member type and values) to JSON or XML and can also go in
reverse to produce a proper C# object from XML/JSON? I'm also open to a
client-side solution. If Ajax.NET is the solution does it provide the functionality for .NET Framework v1.1 C#?
My class data types can be: intrinsic types,
ArrayLists, objects derived from other classes, XmlDocument.
Thanks.