Asp.net Core WebApi returns the JSON automatic hump formatting problem, webapijson

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.