1

I am sending my array of arrays from the client to the server. Using jQuery ajax method after stringify like this

JSON.stringify({ list: FinalList })

and on the server side I am getting it like this

{\"list\":[[\"Full Name\"],[\"Select any one\",\"Option 1\",\"Option 2\",\"Option 3\"],[\"address\"],[\"contact name\"]]}

But I am not able to change it to the original form again. I tried using JavaScriptSerializer but I was not able to get the required result. It's giving me an object.

How I will deserialize it to it's original form?

1

2 Answers 2

2

The Deserialize< T >(String) method in JavaScriptSerializer requires a Type parameter, which tells it which type to deserialize to.

You must have a class which has the same structure as your javascript object (has a List or Array property which name is "list"), like MyType. Then use Deserialize< MyType >(text) to get the correct MyType instance.

And the MyType class should be like this:

public class MyType
{
    public IList<string[]> List { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I had a similar issue that ended up requiring a different solution. I had a complex model with several nested models within, and while I had default/parameterless constructors (it actually gives you a nice 500 error if you don't) I did not new up my nested models within the default constructor. As soon as I instantiated each of these within each of my default constructors, the deserializer was able to build my object perfectly.

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.