zoukankan      html  css  js  c++  java
  • Json序列化循环引用的问题

    今天在发布接口的时候出突然出现了一个问题,报错代码为:

    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;
  • 相关阅读:
    lldb
    错误记录
    越狱后
    c#学习
    26python类
    day01
    第二冲刺阶段第四天
    第二冲刺阶段第三天
    第五周课后作业
    结对作业
  • 原文地址:https://www.cnblogs.com/yanglang/p/9363091.html
Copyright © 2011-2022 走看看