json.net dual -sequentialization problem
When using json.net serialization object, a strange problem may be encountered: the object is dual serialization. This will cause JSON data to be wrapped in dual quotes in the response, and the embedded quotes are also righteous.
root cause
The root cause is the serialization method. If you use JSONCONVERT.SerializeObject (Instance)
if you use JSONCONVERT.SERIALILILILILIALIEOBOCT (Instance). This is because you first serialize it into a string, and then the API controller will further serialize it to the JavaScript string word.
solution
To solve this problem, you only need to return directly to the object:
Public IenuMerable
replacement method
public IEnumerable GetFoobars()
{
var foobars = ...;
return foobars;
}
httpconfiguration : config.Formatters.jsonFormatter.serSettings.converters.add config.Formatters.jsonFormatter.Serializersettings.ConVerters.add (new barconverter ());
other tips
Make sure that the custom converter is correctly implemented.
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new FooConverter());
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new BarConverter());
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3