WebApi——json返回多了 k_BackingField
产生原因:
model类添加了 [System.Serializable]
解决方案:
xxxxx.WebApi\App_Start\WebApiConfig.cs的Register函数中添加如下代码
config.Formatters.XmlFormatter.UseXmlSerializer = true;
config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "xml", "application/xml"));
config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "xml", "application/xml"));
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; var serializerSettings =
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
var contractResolver =
(DefaultContractResolver)serializerSettings.ContractResolver;
contractResolver.IgnoreSerializableAttribute = true;
//config.Formatters.Insert(0, new JsonpFormatter());
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "json", "application/json"));
config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "json", "application/json"));
WebApi——json返回多了 k_BackingField的更多相关文章
- .NET Core 处理 WebAPI JSON 返回烦人的null为空
前言 项目开发中不管是前台还是后台都会遇到烦人的null,数据库表中字段允许空值,则代码实体类中对应的字段类型为可空类型Nullable<>,如int?,DateTime?,null值字段 ...
- ASP.NET Core webapi json 返回时间格式问题
网站找了几个方案不好使,比如: 1: services.AddMvc().AddJsonOptions(opt => { opt.SerializerSettings.DateFormatStr ...
- 如何让webapi只返回json格式数据
最近脑子不好用,总记不住事,以前搞过让webapi只返回json格式的数据,今天有人问我又突然想不起了,后来总结一下,备忘一下,大概有下面几种处理方式 1.在WebApiConfig类的Registe ...
- 修改 mvc webapi 默认返回 json 格式
web api 默认的已 xml 格式返回数据 现在开发一般都是以 json 格式为主 下面配置让 webapi 默认返回 json ,在需要返回 xml 时只需要加一个查询参数 datatype=x ...
- VB 老旧版本维护系列---尴尬的webapi访问返回json对象
尴尬的webapi访问返回json对象 首先Imports Newtonsoft.Json Imports MSXML2(Interop.MSXML2.dll) Dim URLEncode As Sy ...
- WebApi接口返回json,xml,text纯文本等
[Route("api/Message/MessageList/")] [HttpGet] public HttpResponseMessage MessageList() { R ...
- C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解 ...
- webapi的返回类型,webapi返回图片
1.0 首先是返回常用的系统类型,当然这些返回方式不常用到.如:int,string,list,array等.这些类型直接返回即可. public List<string> Get() { ...
- WebApi 接口返回值类型详解 ( 转 )
使用过Webapi的园友应该都知道,Webapi的接口返回值主要有四种类型 void无返回值 IHttpActionResult HttpResponseMessage 自定义类型 此篇就围绕这四块分 ...
随机推荐
- 【Python练习】文件引用用户名密码登录系统
一.通过txt文件引入用户名密码 1 #coding=utf-8 from selenium import webdriver #from selenium.common.exceptions imp ...
- Linux发展历史图
Linux发展历史图 http://futurist.se/gldt/wp-content/uploads/12.10/gldt1210.svg
- Java-idea-设置类头注释和方法注释
一.文件级别的注释 主要是通过File-->Setting-->Editor→File and Code Template中来设置 可以再右侧include中设置File ...
- transition使用
- [LeetCode] 697. Degree of an Array_Easy tag: Hash Table
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...
- [LeetCode] questions conclustion_Path in Tree
Path in Tree: [LeetCode] 112. Path Sum_Easy tag: DFS input: root, target, return True if exi ...
- 4.keras实现-->生成式深度学习之DeepDream
DeepDream是一种艺术性的图像修改技术,它用到了卷积神经网络学到的表示,DeepDream由Google于2015年发布.这个算法与卷积神经网络过滤器可视化技术几乎相同,都是反向运行一个卷积神经 ...
- Lintcode: Find Peak Element
There is an integer array which has the following features: * The numbers in adjacent positions are ...
- Rpgmaker开发心得(1)且事件
例:NPC让你给他桃子和梨子,然后给你西瓜. 实际就是:有桃子且有梨子时的判断,但对于大多数不会直接编写脚本的同学,最好的方式就是使用开关. 思路如下: var:变量 on:开关 if(on西瓜=on ...
- lnmp1.4 安装php fileinfo扩展 方法
第一步:在lnmp1.4找到php安装的版本 使用命令 tar -jxvf php-7.1.7.tar.bz2 解压 第二步: 在解压的php-7.1.7文件夹里找到fileinfo文件夹,然 ...