Asp.net Core WebApi returns the JSON automatic hump formatting problem, webapijson
Starting from today, I officially started the development of Asp.net Core. It is estimated that I will write blogs frequently recently to record various pitfalls encountered in Asp.net Core.
The first problem is: by default, the returned json is automatically formatted as a camper style through the webapi written by core, and is not returned according to the specific class name. How can I get it returned according to the class name?
Public void ConfigureServices (IServiceCollection services) {// Add framework services. services. addApplicationInsightsTelemetry (Configuration); services. addMvc (). addJsonOptions (options => {options. serializerSettings. contractResolver = new DefaultContractResolver ();});;}
In the Startup. cs global configuration class, add the json configuration option to solve the problem, and do not forget to reference: using Newtonsoft. Json. Serialization;
{"Statuz": 0, "ErrorMsg": "obtained successfully", "Data": [{"Name": "xxx", "MobilePhone": "15xxxx81xxx ", "Sex": "0", "Score":-102}, {"Name": "xxxxx", "MobilePhone": "15xxxxx1xx1", "Sex ": "0", "Score":-102}]}
The return value is refreshing.
Reference: http://www.cnblogs.com/zhong-ken/p/6062782.html