开发者

when we use JavaScriptSerializer deserializer? [closed]

开发者 https://www.devze.com 2023-02-22 03:48 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消