when we use JavaScriptSerializer deserializer? [closed]
can开发者_如何学运维 u explain this with example.
Well, "for example"...
Say I'm creating an MVC controller that handles a bunch of actions for a bunch of views. In one of the views, there's some custom AJAX code (for the purpose of the example, let's say I'm using an AJAX call to load data into a jqGrid) which needs to get data from the server.
In this case, a quick and easy solution would be to add another action to the controller which returns a JSON result. This action would be called by the AJAX request to get the data. Within this action, I'd fetch the models I need for the data and use the JavaScriptSerializer
to serialize them to be returned as a JSON result.
well... basically you can take an object and serialize it into json to be worked with in jquery/javascript...
I'm sure there are plenty of other things you can do with it... but your question is to broad to really narrow it down.
Just to throw this out there... but Google is a good place to start: JavaScriptSerializer
to "deserialize" the serialized data... (most of the time you're going to be doing this on the receiving end of an Ajax call) and in that case using jquery $.ajax automatically turns the json data into an object when you specify the data type as "json"
If your looking to do the deserialization in c# on the server side... well.. there are methods for that... JavaScriptSerializer.Deserialize - how to change field names
精彩评论