Reputation: 4692
In the following link, a .Net object is passed in an Ajax call using the json2.js javascript library.
http://encosia.com/using-complex-types-to-make-calling-services-less-complex/
Is there a similar method using the Json.Net javascript libary? I can't find anything on it...
I know how to serialize and deserialize objects using this library, but it's all done on the server side.
What if I need to serialize an object on the client side similar to the call in the above link? Anything available using the Json.Net library?
Upvotes: 1
Views: 1375
Reputation: 129657
I think you have some misconceptions here. Json.Net is a third-party JSON library written for .NET in C#. There is no javascript component to it at all. It is commonly used on servers to deserialize requests from, and serialize responses to, clients, which may or may not be javascript-based. The library could also be used in a C#-based client.
The article you referenced demonstrates creating a javascript object and serializing it to JSON using the stringify
method from the json2.js library. The resulting serialized string is then sent to a server using jQuery ajax call, and is handled by an ASMX WebMethod.
I have to point out that that article was written in June 2009. Nowadays (nearly 5 years later), most browsers have built-in support for JSON serialization using the very same stringify
method syntax shown in the article. So you don't even need a third-party library for that, just call JSON.stringify()
directly. For those browsers that don't support it, you can still use json2.js.
Similarly, there are newer, better technologies available on the server side than ASMX, for example ASP.NET Web API, which uses Json.Net by default behind the scenes.
Upvotes: 1