I have a custom Javascript object that has a few string and float members. I'd like to serialize an array of them in Javascript, assign the result to a hidden field, and then retrieve and deserialize them in the codebehind for my asp application.
Is there a standard way to do this?
I have a custom Javascript object that has a few string and float members. I'd like to serialize an array of them in Javascript, assign the result to a hidden field, and then retrieve and deserialize them in the codebehind for my asp application.
Is there a standard way to do this?
Share Improve this question edited Oct 1, 2010 at 9:14 NibblyPig asked Oct 1, 2010 at 8:46 NibblyPigNibblyPig 53k75 gold badges218 silver badges380 bronze badges 1- I clarified my question because it wasn't clear before that I want to serialize to JSON in javascript – NibblyPig Commented Oct 1, 2010 at 9:14
3 Answers
Reset to default 3You can Use JSON.
With JSON you serialize data and serialize it in Different language.
http://flexjson.sourceforge/
http://forums.c-sharpcorner./Blogs/BlogDetail.aspx?BlogId=2028
http://www.nateirwin/2008/11/20/json-array-to-c-using-jsonnet/
http://msdn.microsoft./en-us/library/bb299886.aspx
http://www.codeproject./Tips/79435/Deserialize-JSON-with-Csharp.aspx
what you need is JSON
.
both javascript and C# can handle it.
article: http://www.nateirwin/2008/11/20/json-array-to-c-using-jsonnet/
also: http://www.json/ (scroll to the end)
Check this answer How do I serialize a C# anonymous type to a JSON string?
Edit:
Since JavaScriptSerializer
is deprecated .. you can use DataContractJsonSerializer
.
MSDN: DataContractJsonSerializer
Blog post on how to use it: http://pietschsoft./post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx