久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='GwEOz'><style id='GwEOz'><dir id='GwEOz'><q id='GwEOz'></q></dir></style></legend>

    1. <small id='GwEOz'></small><noframes id='GwEOz'>

          <bdo id='GwEOz'></bdo><ul id='GwEOz'></ul>

        <i id='GwEOz'><tr id='GwEOz'><dt id='GwEOz'><q id='GwEOz'><span id='GwEOz'><b id='GwEOz'><form id='GwEOz'><ins id='GwEOz'></ins><ul id='GwEOz'></ul><sub id='GwEOz'></sub></form><legend id='GwEOz'></legend><bdo id='GwEOz'><pre id='GwEOz'><center id='GwEOz'></center></pre></bdo></b><th id='GwEOz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GwEOz'><tfoot id='GwEOz'></tfoot><dl id='GwEOz'><fieldset id='GwEOz'></fieldset></dl></div>
        <tfoot id='GwEOz'></tfoot>

        JSON.NET 錯(cuò)誤檢測(cè)到類型的自引用循環(huán)

        JSON.NET Error Self referencing loop detected for type(JSON.NET 錯(cuò)誤檢測(cè)到類型的自引用循環(huán))

          • <small id='YouFR'></small><noframes id='YouFR'>

              <tbody id='YouFR'></tbody>
            <i id='YouFR'><tr id='YouFR'><dt id='YouFR'><q id='YouFR'><span id='YouFR'><b id='YouFR'><form id='YouFR'><ins id='YouFR'></ins><ul id='YouFR'></ul><sub id='YouFR'></sub></form><legend id='YouFR'></legend><bdo id='YouFR'><pre id='YouFR'><center id='YouFR'></center></pre></bdo></b><th id='YouFR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YouFR'><tfoot id='YouFR'></tfoot><dl id='YouFR'><fieldset id='YouFR'></fieldset></dl></div>
            <tfoot id='YouFR'></tfoot>
                <legend id='YouFR'><style id='YouFR'><dir id='YouFR'><q id='YouFR'></q></dir></style></legend>
                  <bdo id='YouFR'></bdo><ul id='YouFR'></ul>
                  本文介紹了JSON.NET 錯(cuò)誤檢測(cè)到類型的自引用循環(huán)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我嘗試序列化從 Entity Data Model .edmx 和我使用時(shí)自動(dòng)生成的 POCO 類

                  I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used

                  JsonConvert.SerializeObject 
                  

                  我收到以下錯(cuò)誤:

                  檢測(cè)到類型 System.data.entity 的錯(cuò)誤自引用循環(huán)發(fā)生.

                  Error Self referencing loop detected for type System.data.entity occurs.

                  我該如何解決這個(gè)問(wèn)題?

                  How do I solve this problem?

                  推薦答案

                  這是最好的解決方案https://docs.microsoft.com/en-us/archive/blogs/hongyes/loop-reference-handling-in-web-api

                  (我已經(jīng)選擇/嘗試過(guò)這個(gè),和其他許多人一樣)

                  json.net 序列化程序有一個(gè)忽略循環(huán)引用的選項(xiàng).將以下代碼放入 WebApiConfig.cs 文件中:

                  The json.net serializer has an option to ignore circular references. Put the following code in WebApiConfig.cs file:

                   config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling 
                  = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 
                  

                  簡(jiǎn)單的修復(fù)將使序列化程序忽略將導(dǎo)致循環(huán)的引用.但是,它有局限性:

                  The simple fix will make serializer to ignore the reference which will cause a loop. However, it has limitations:

                  • 數(shù)據(jù)丟失循環(huán)引用信息
                  • 修復(fù)僅適用于 JSON.net
                  • 如果有很深的引用鏈,則無(wú)法控制引用的級(jí)別

                  如果你想在非 api 的 ASP.NET 項(xiàng)目中使用這個(gè)修復(fù),你可以在 Global.asax.cs 中添加上述行,但首先添加:

                  If you want to use this fix in a non-api ASP.NET project, you can add the above line to Global.asax.cs, but first add:

                  var config = GlobalConfiguration.Configuration;
                  

                  如果你想在 .Net Core 項(xiàng)目中使用它,你可以將 Startup.cs 更改為:

                  If you want to use this in .Net Core project, you can change Startup.cs as:

                    var mvc = services.AddMvc(options =>
                          {
                             ...
                          })
                          .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
                  

                  修復(fù) 2:全局保留循環(huán)引用

                  第二個(gè)修復(fù)與第一個(gè)類似.只需將代碼更改為:

                  Fix 2: Preserving circular reference globally

                  This second fix is similar to the first. Just change the code to:

                  config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling 
                       = Newtonsoft.Json.ReferenceLoopHandling.Serialize;     
                  config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling 
                       = Newtonsoft.Json.PreserveReferencesHandling.Objects;
                  

                  應(yīng)用此設(shè)置后,數(shù)據(jù)形狀將發(fā)生變化.

                  The data shape will be changed after applying this setting.

                  [
                     {
                        "$id":"1",
                        "Category":{
                           "$id":"2",
                           "Products":[
                              {
                                 "$id":"3",
                                 "Category":{
                                    "$ref":"2"
                                 },
                                 "Id":2,
                                 "Name":"Yogurt"
                              },
                              {
                                 "$ref":"1"
                              }
                           ],
                           "Id":1,
                           "Name":"Diary"
                        },
                        "Id":1,
                        "Name":"Whole Milk"
                     },
                     {
                        "$ref":"3"
                     }
                  ]
                  

                  $id 和 $ref 保留所有引用并使對(duì)象圖級(jí)別平坦,但客戶端代碼需要知道形狀更改才能使用數(shù)據(jù),并且它也僅適用于 JSON.NET 序列化程序.

                  The $id and $ref keeps the all the references and makes the object graph level flat, but the client code needs to know the shape change to consume the data and it only applies to JSON.NET serializer as well.

                  此修復(fù)是在模型類上裝飾屬性以控制模型或?qū)傩约?jí)別的序列化行為.要忽略該屬性:

                  This fix is decorate attributes on model class to control the serialization behavior on model or property level. To ignore the property:

                   public class Category 
                      { 
                          public int Id { get; set; } 
                          public string Name { get; set; } 
                         
                          [JsonIgnore] 
                          [IgnoreDataMember] 
                          public virtual ICollection<Product> Products { get; set; } 
                      } 
                  

                  JsonIgnore 用于 JSON.NET,IgnoreDataMember 用于 XmlDCSerializer.保留參考:

                  JsonIgnore is for JSON.NET and IgnoreDataMember is for XmlDCSerializer. To preserve reference:

                   // Fix 3 
                          [JsonObject(IsReference = true)] 
                          public class Category 
                          { 
                              public int Id { get; set; } 
                              public string Name { get; set; } 
                           
                             // Fix 3 
                             //[JsonIgnore] 
                             //[IgnoreDataMember] 
                             public virtual ICollection<Product> Products { get; set; } 
                         } 
                          
                         [DataContract(IsReference = true)] 
                         public class Product 
                         { 
                             [Key] 
                             public int Id { get; set; } 
                          
                             [DataMember] 
                             public string Name { get; set; } 
                          
                             [DataMember] 
                             public virtual Category Category { get; set; } 
                         }
                  

                  JsonObject(IsReference = true)] 用于 JSON.NET,[DataContract(IsReference = true)] 用于 XmlDCSerializer.注意:在類上應(yīng)用DataContract后,需要將DataMember添加到要序列化的屬性中.

                  JsonObject(IsReference = true)] is for JSON.NET and [DataContract(IsReference = true)] is for XmlDCSerializer. Note that: after applying DataContract on class, you need to add DataMember to properties that you want to serialize.

                  這些屬性可以應(yīng)用在 json 和 xml 序列化器上,并提供對(duì)模型類的更多控制.

                  The attributes can be applied on both json and xml serializer and gives more controls on model class.

                  這篇關(guān)于JSON.NET 錯(cuò)誤檢測(cè)到類型的自引用循環(huán)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時(shí)忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯(cuò)誤的 XML)

                      • <legend id='KSDr4'><style id='KSDr4'><dir id='KSDr4'><q id='KSDr4'></q></dir></style></legend>

                        <small id='KSDr4'></small><noframes id='KSDr4'>

                          <bdo id='KSDr4'></bdo><ul id='KSDr4'></ul>
                          <i id='KSDr4'><tr id='KSDr4'><dt id='KSDr4'><q id='KSDr4'><span id='KSDr4'><b id='KSDr4'><form id='KSDr4'><ins id='KSDr4'></ins><ul id='KSDr4'></ul><sub id='KSDr4'></sub></form><legend id='KSDr4'></legend><bdo id='KSDr4'><pre id='KSDr4'><center id='KSDr4'></center></pre></bdo></b><th id='KSDr4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KSDr4'><tfoot id='KSDr4'></tfoot><dl id='KSDr4'><fieldset id='KSDr4'></fieldset></dl></div>
                          • <tfoot id='KSDr4'></tfoot>
                              <tbody id='KSDr4'></tbody>

                            主站蜘蛛池模板: 精品免费国产一区二区三区四区介绍 | 在线第一页 | 国产精品久久久久久亚洲调教 | 亚洲不卡在线观看 | 国产精品国产亚洲精品看不卡15 | 欧美女优在线观看 | av一区在线观看 | 欧美区日韩区 | 伊人看片 | 最新中文字幕在线播放 | 日本二区在线观看 | 亚洲国产精品一区二区www | 国产精品一区二区三区久久 | 国产亚洲精品久久19p | 五月槐花香 | 亚洲 欧美 激情 另类 校园 | 奇米久久久| 久久久国产一区二区三区四区小说 | 成人在线观看免费视频 | 国内自拍偷拍一区 | 亚洲欧美日韩久久 | 一区二区三区四区在线播放 | 综合欧美亚洲 | 国产精品免费观看 | 成人精品视频99在线观看免费 | 中文字幕一区二区三区精彩视频 | 色精品| 亚洲欧洲成人 | 日韩欧美视频网站 | jizz视频| 精品99在线| 久久99网 | 国产成人精品一区二三区在线观看 | 6080亚洲精品一区二区 | 欧美性大战久久久久久久蜜臀 | 97精品超碰一区二区三区 | 国产视频一区在线观看 | 国产精品污污视频 | 国内自拍视频在线观看 | 久久高清国产视频 | 国产精品国产成人国产三级 |