Json Self referencing loop detected
Self referencing loop detected......的错误
解决方案:
1 增加 [JsonIgnore] 过滤关联,使其不参与序列化。
这个方法简单粗暴。但是你就没办法获取关联的json对象。
2 序列化时,使用如下代码,list是model对象(只适合关联对象较少)
(但是经过楼主测试,关联比较多,比较复杂时,还是没卵用,直接卡死。这个问题的原因呼之欲出,也是由于主外键对象互相深度循环,牵涉到的实体层较多,关联对象更多,就不赘述了)
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
string result = JsonConvert.SerializeObject(list, settings);
为了引用方便,我们可以作为扩展方法:
public static class Extension
{
public static string ToJsonString<T>(this T list)
{
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
string result = JsonConvert.SerializeObject(list, settings);
return result;
}
}
Json Self referencing loop detected的更多相关文章
- JSON.NET的Self referencing loop detected with type的原因以及解决办法
模型中有循环引用是很常见的.例如,以下模型显示双向导航属性: : public class Category : { : public Category() : { : Products = new ...
- c# json 序列化时遇到错误 error Self referencing loop detected for type
参考网址:http://blog.csdn.net/adenfeng/article/details/41622255 在写redis缓存帮助类的时候遇到的这个问题,本来打算先序列化一个实体为json ...
- .NET JSON 转换 Error ” Self referencing loop detected for type“
在进行实体转换为Json格式报错如下图: Self referencing loop detected for property 'md_agent' with type 'System.Data.E ...
- Self referencing loop detected with type
json.net namespace EFDAL{ using System; using System.Collections.Generic; using Newtonsoft. ...
- codefirst mvc Self referencing loop detected for property
登录时,json序列化用户类时提示错误"Self referencing loop detected for property--",经过5个小时的查找,发现原因可能是,用户类包含 ...
- Self referencing loop detected for property 错误
EF 序列化返回json时 报错:Self referencing loop detected for property 解决方案:在webapiconfig.cs文件中,增加设置: 1.config ...
- EF关于报错Self referencing loop detected with type的原因以及解决办法
1)具体报错 { "Message": "出现错误.", "ExceptionMessage": "“ObjectContent` ...
- Request failed with status code 500以及自引用循环Self referencing loop detected for property ‘xx‘ with type
错误Error: Request failed with status code 500 ,调试前端没问题,后端也没问题,还报错"连接超时" 在Network中找到错误Self r ...
- Newtonsoft.Json转换强类型DataTable错误:Self referencing loop detected with type ......
问题,在使用Newtonsoft.Json对强类型的DataTable进行系列化时会出现循环引用错误 解决办法,不要直接系列化强类型的DataTable,改为 JsonConvert.Serializ ...
随机推荐
- DNS主从复制及区域传送
前言 DNS主从复制,就是将主DNS服务器的解析库复制传送至从DNS服务器,进而从服务器就可以进行正向.反向解析了.从服务器向主服务器查询更新数据,保证数据一致性,此为区域传送.也可以说,DNS区域传 ...
- 9-(基础入门篇)云端安装MQTT服务器
https://www.cnblogs.com/yangfengwu/p/9953703.html 记得把文件拷贝到上一节配置的和云端共享的那个盘里面,好拷贝文件到云服务器 进入到bin目录 咱先以控 ...
- 利用H5本地存储localStorage、sessionStorage
最近的业务处理上,要使用cookie缓存储一下数据,公司的cookie还搞出点问题.而用户的浏览器都是利用微信的内置,普遍支持h5的本地存储.于是利用了这个... 现代浏览器普遍开始支持H5本地存储, ...
- 微信小程序日常开发中常遇到的错误代码
在开发过程中,会遇到很多微信返回的状态码,鬼知道代表什么意思,现在好了,整理总结了一份状态码,方便大家. 微信小程序错误码参考 状态码(场景值) 说明 -1 系统繁忙 0 请求成功 40001 ...
- python第二周。2019.4.13
1, 我绘制大蟒蛇就是..保存也对着呢,你要是打开文件的话,先闪个黑屏,再闪个白屏..自动退出,然后啥都没了. 我觉得是我代码编错了...再来一遍! 这次到可以,但是这个大蟒蛇好像没有回头... 刚才 ...
- VitualBox安装linux记录
下载镜像 CentOS 7镜像下载 阿里云站点:http://mirrors.aliyun.com/centos/7/isos/x86_64/ VirtualBox安装linux https://ww ...
- monkey测试基础
一.环境配置 Java JDK和android SDK 二.基本命令 *安卓手机链接电脑,打开手机的开发者模式,允许usb调试 adb:检查adb是否安装成功 adb devices:查看连接的设备 ...
- Redis Cluster日常操作命令梳理
在之前的一篇文章已经介绍了Redis Cluster及其部署,下面说下Redis Cluster日常操作命令: 一.以下命令是Redis Cluster集群所独有的,执行下面命令需要先登录redis: ...
- kvm虚拟化管理平台WebVirtMgr部署-完整记录(0)
打算部署kvm虚拟机环境,下面是虚拟化部署前的一些准备工作: 操作系统环境安装1)修改内核模式为兼容内核启动[root@ops ~]# uname -aLinux openstack 2.6.32-4 ...
- Kruskal算法-HDU1863畅通工程
链接 [http://acm.hdu.edu.cn/showproblem.php?pid=1863] 题意 Problem Description 省政府"畅通工程"的目标是使全 ...