How is asp.net MVC serialized for a Json object for controller actions?

How is asp.net MVC serialized for a Json object for controller actions?

For example, I have a custom object, and if you send an ajax request with JSON objects to a server action

public ActionResult(List<CustomObject> abc) { // Object is serialized automatically how MVC is doing it is the question. } 

The reason why I ask about this is because some of my objects do not have proper serialization and therefore there is data loss, then I have to go back to the old string value method for serializaiton.

 public ActionResult(string abc) { JavaScriptSerializer serializer = new JavaScriptSerializer(); List<CustomObject> lstabc = serializer.Deserialize<List<CustomObject>>(abc); } 

Which I would like to avoid, and secondly, what are the best libraries for serializing JSON MVC Asp.net objects?

+2
source share
1 answer

A model binder is taken from deserialization.

if you find that it doesn’t work, you can create your own connecting device and register it using the framework - this should mean that you can avoid all the noise of deserialization in your controllers.

There are several links to explain this and how to implement a custom mediation in the following SO question:

ASP.Net MVC Custom Model Binding Description

One of the most popular json serialization libraries is the newtonsoft json.net library - I have used it effectively many times:

http://james.newtonking.com/pages/json-net.aspx

Good luck

+1
source

Source: https://habr.com/ru/post/1411042/


All Articles