Json序列化循环引用的问题
2024-10-16 23:45:19
今天在发布接口的时候出突然出现了一个问题,报错代码为:
1 An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'.
2 Exception message: Self referencing loop detected for property '******' with type '******'. Path '[0].******[0]'.
经过研究,解决方法如下:
找到相应的属性,添加 attribute:[IgnoreDataMember]
还有时候会出现特殊情况,即使标记以上的attribute也不能解决
具体错误为:
Newtonsoft.Json.JsonSerializationException 时 Self referencing loop detected for property *****
可以在web api的config中(WebApiConfig.cs)添加一下代码,用以过滤掉此问题
奉上代码:
1 config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
最新文章
- 随机记录工作中常见的sql用法错误(一)
- PHP webservice的使用
- Prince2七大原则(4)
- 【 2013 Multi-University Training Contest 2 】
- php连接sql server
- makefile自动生成依赖关系
- sublime text配置记录
- smali语法中文版
- R语言与数据分析
- clientX,screenX,pageX,offsetX的异同 【转载】
- Oracle DataGuard搭建(一)
- What is therelationship between @EJB and ejb-ref/ejb-local-ref?
- Activity数据传输到服务
- UVa 908 - Re-connecting Computer Sites
- linux下的数据库管理工具phpmyadmin安装以及文件大小限制的配置修改
- ping 返回的TTL数值代表什么?
- Oracle 12c 添加scott用户
- rocketmq 学习记录-2
- oracle如何链接到另外一个数据库DB_LINK
- java基础-day5
热门文章
- php5.6.40编译安装
- Python:基础知识
- HDU 1203 I NEED A OFFER!(01背包+简单概率知识)
- 编译最新的SQLite 3.8.4.3为一个DLL
- Android 网络编程之---HttpClient 与 HttpURLConnection 共用cookie
- SAP调用RestfulApi接口接收数据
- Express app.listen 函数了解
- Selenium 爬取全国水质周报Word
- 欧几里得算法(及扩展)&;&;快速幂(二分+位运算)
- C指针乱谈(1)