1

From this site, I've learned that ASP.NET script services accepting JSON actually require them to be serialized JSON strings (see: "JSON, objects, and strings: oh my!" section of the link). Is there a quick and easy way to serialize them for ASP.NET AJAX consumption on the client side instead of trying to manually convert a bunch of existing objects to JSON-looking strings?

Thanks in advance!

2 Answers 2

2

You can use JSON.stringify() to serialize client-side objects for consumption in ASP.NET's Script Services.

Using that approach, you can map client-side objects to server-side objects very easily. ASP.NET will automatically handle converting the JSON to objects (or even collections of objects) for you.

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

Comments

0

The article writer is confusing Javascript objects with JSON strings. There is no such thing as a "JSON object".

Naturally if you try to send an object to a web service, it has to be serialised, as the request data can only contain text, not objects. The standard way of serialising data to be posted is URL encoding it, so that is what jQuery does.

There is no JSON serialisation built into Javascript or jQuery. You would have to do the serialising yourself or find a library that does it. Here are some options: Serializing to JSON in jQuery


Also, the data sent in the example is not valid JSON. It looks like this:

"{'fname':'dave', 'lname':'ward'}"

To be valid JSON it should look like this:

'{"fname":"dave", "lname":"ward"}'

1 Comment

Upvoted to offset the downvote. Thanks for adding some more explanation.

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.