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的更多相关文章

  1. JSON.NET的Self referencing loop detected with type的原因以及解决办法

    模型中有循环引用是很常见的.例如,以下模型显示双向导航属性: : public class Category : { : public Category() : { : Products = new ...

  2. c# json 序列化时遇到错误 error Self referencing loop detected for type

    参考网址:http://blog.csdn.net/adenfeng/article/details/41622255 在写redis缓存帮助类的时候遇到的这个问题,本来打算先序列化一个实体为json ...

  3. .NET JSON 转换 Error ” Self referencing loop detected for type“

    在进行实体转换为Json格式报错如下图: Self referencing loop detected for property 'md_agent' with type 'System.Data.E ...

  4. Self referencing loop detected with type

    json.net namespace EFDAL{    using System;    using System.Collections.Generic;    using Newtonsoft. ...

  5. codefirst mvc Self referencing loop detected for property

    登录时,json序列化用户类时提示错误"Self referencing loop detected for property--",经过5个小时的查找,发现原因可能是,用户类包含 ...

  6. Self referencing loop detected for property 错误

    EF 序列化返回json时 报错:Self referencing loop detected for property 解决方案:在webapiconfig.cs文件中,增加设置: 1.config ...

  7. EF关于报错Self referencing loop detected with type的原因以及解决办法

    1)具体报错 { "Message": "出现错误.", "ExceptionMessage": "“ObjectContent` ...

  8. 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 ...

  9. Newtonsoft.Json转换强类型DataTable错误:Self referencing loop detected with type ......

    问题,在使用Newtonsoft.Json对强类型的DataTable进行系列化时会出现循环引用错误 解决办法,不要直接系列化强类型的DataTable,改为 JsonConvert.Serializ ...

随机推荐

  1. JavaScript中的slice函数

    String.slice(start,end)returns a string containing a slice, or substring, of string. It does not mod ...

  2. 开发板测试-Wi-Fi

    一,下载STM32程序 1,方式一,串口下载(其他下载方式在最后补充) ①调整拨动开关位置 → 短接BOOT0和3.3V → 复位STM32 ②打开下载软件,下载程序 去掉短接 ③测试 {data:s ...

  3. 17-(基础入门篇)GPRS(Air202)串口

    https://www.cnblogs.com/yangfengwu/p/9968716.html 现在看一下官方给的demo 其实只要有两个就好说了 module(...,package.seeal ...

  4. 什么是Mixin模式:带实现的协议

    Mixin(织入)模式并不是GOF的<设计模式>归纳中的一种,但是在各种语言以及框架都会发现该模式(或者思想)的一些应用.简单来说,Mixin是带有全部实现或者部分实现的接口,其主要作用是 ...

  5. 自行实现高性能MVC

    wcf虽然功能多.扩展性强但是也面临配置忒多,而且restful的功能相当怪异,并且目前没法移植.asp.net core虽然支持webapi,但是功能也相对繁多.配置复杂.就没有一个能让码农们安安心 ...

  6. Luogu4768 NOI2018 归程 最短路、Kruskal重构树

    传送门 题意:给出一个$N$个点.$M$条边的图,每条边有长度和海拔,$Q$组询问,每一次询问从$v$开始,经过海拔超过$p$的边所能到达的所有点中到点$1$的最短路的最小值,强制在线.$N \leq ...

  7. 读取Excel的记录并导入SQL数据库

    准备一下,近段时间,需要把Excel的数据导入数据库中. 引用命名空间: using System.Configuration; using System.Data; using System.Dat ...

  8. DeskMini无传统机械键盘与鼠标接口的情况下使用U盘安装系统经验总结

    总结安装纯净版Win7旗舰版系统安装过程所解决的问题要点: 1:UEFI引导启动的实现. 2:使用Dism++实现系统的安装. 3:使用Dism++解决新主板在安装系统过程中不能使用USB键盘和鼠标的 ...

  9. MySQL调优基础, 与hikari数据库连接池配合

    1.根据硬件配置系统参数 wait_timeout  非交互连接的最大存活时间, 10-30min max_connections   全局最大连接数 默认100 根据情况调整 back_log   ...

  10. 面试2——java基础3

    21.Http请求的get和post的区别? get:从 指定的资源请求数据.请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的 post:向指定的资源提交要被处理的数据.请注意, ...