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.

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"}'
2
  • Why the downvote? If you don't explain what you think is wrong, it can't improve the answer.
    – Guffa
    Jul 14, 2011 at 23:09
  • Upvoted to offset the downvote. Thanks for adding some more explanation.
    – Ocelot20
    Jul 15, 2011 at 12:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.