4

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.net application.

Is there a standard way to do this?

1
  • I clarified my question because it wasn't clear before that I want to serialize to JSON in javascript Commented Oct 1, 2010 at 9:14

3 Answers 3

3

You can Use JSON.

With JSON you serialize data and serialize it in Different language.

http://flexjson.sourceforge.net/

http://forums.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=2028

http://www.nateirwin.net/2008/11/20/json-array-to-c-using-jsonnet/

http://msdn.microsoft.com/en-us/library/bb299886.aspx

http://www.codeproject.com/Tips/79435/Deserialize-JSON-with-Csharp.aspx

Sign up to request clarification or add additional context in comments.

Comments

2

what you need is JSON.

both javascript and C# can handle it.

article: http://www.nateirwin.net/2008/11/20/json-array-to-c-using-jsonnet/

also: http://www.json.org/ (scroll to the end)

4 Comments

So is there a native serializer in javascript to serialize to JSON? I want to avoid more plugins where possible, especially dlls for .net
JSON IS javascript. it stands for JavaScript Object Notation. In asp.net you might need a dll.
So how do I convert a javascript object to JSON, in javascript, so I can pop it into a hidden field and handle it on submit?
2

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.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.