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

<tfoot id='wKKpk'></tfoot>

  1. <legend id='wKKpk'><style id='wKKpk'><dir id='wKKpk'><q id='wKKpk'></q></dir></style></legend>
    • <bdo id='wKKpk'></bdo><ul id='wKKpk'></ul>
  2. <small id='wKKpk'></small><noframes id='wKKpk'>

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

      在 JSON.NET 中反序列化的轉換接口

      Casting interfaces for deserialization in JSON.NET(在 JSON.NET 中反序列化的轉換接口)

        <tbody id='4B6kj'></tbody>

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

          <legend id='4B6kj'><style id='4B6kj'><dir id='4B6kj'><q id='4B6kj'></q></dir></style></legend>
            <bdo id='4B6kj'></bdo><ul id='4B6kj'></ul>

            <small id='4B6kj'></small><noframes id='4B6kj'>

                本文介紹了在 JSON.NET 中反序列化的轉換接口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試設置一個閱讀器,它將接收來自各種網站的 JSON 對象(想想信息抓取)并將它們翻譯成 C# 對象.我目前正在使用 JSON.NET 進行反序列化過程.我遇到的問題是它不知道如何處理類中的接口級屬性.所以自然的東西:

                I am trying to set up a reader that will take in JSON objects from various websites (think information scraping) and translate them into C# objects. I am currently using JSON.NET for the deserialization process. The problem I am running into is that it does not know how to handle interface-level properties in a class. So something of the nature:

                public IThingy Thing
                

                會產生錯誤:

                無法創建 IThingy 類型的實例.類型是接口或抽象類,不能實例化.

                Could not create an instance of type IThingy. Type is an interface or abstract class and cannot be instantiated.

                相對于 Thingy,讓它成為 IThingy 相對重要,因為我正在處理的代碼被認為是敏感的,并且單元測試非常重要.對于像 Thingy 這樣成熟的對象,無法模擬原子測試腳本的對象.它們必須是一個接口.

                It is relatively important to have it be an IThingy as opposed to a Thingy since the code I am working on is considered sensitive and unit testing is highly important. Mocking of objects for atomic test scripts is not possible with fully-fledged objects like Thingy. They must be an interface.

                我已經研究 JSON.NET 的文檔一段時間了,我在這個網站上找到的與此相關的問題都是一年多以前的.有什么幫助嗎?

                I've been poring over JSON.NET's documentation for a while now, and the questions I could find on this site related to this are all from over a year ago. Any help?

                另外,如果重要的話,我的應用程序是用 .NET 4.0 編寫的.

                Also, if it matters, my app is written in .NET 4.0.

                推薦答案

                @SamualDavis 在 相關問題,我這里總結一下.

                @SamualDavis provided a great solution in a related question, which I'll summarize here.

                如果您必須將 JSON 流反序列化為具有接口屬性的具體類,則可以將具體類作為參數包含到該類的構造函數中! NewtonSoft 反序列化器足夠聰明,可以計算它需要使用那些具體的類來反序列化屬性.

                If you have to deserialize a JSON stream into a concrete class that has interface properties, you can include the concrete classes as parameters to a constructor for the class! The NewtonSoft deserializer is smart enough to figure out that it needs to use those concrete classes to deserialize the properties.

                這是一個例子:

                public class Visit : IVisit
                {
                    /// <summary>
                    /// This constructor is required for the JSON deserializer to be able
                    /// to identify concrete classes to use when deserializing the interface properties.
                    /// </summary>
                    public Visit(MyLocation location, Guest guest)
                    {
                        Location = location;
                        Guest = guest;
                    }
                    public long VisitId { get; set; }
                    public ILocation Location { get;  set; }
                    public DateTime VisitDate { get; set; }
                    public IGuest Guest { get; set; }
                }
                

                這篇關于在 JSON.NET 中反序列化的轉換接口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                Parse malformed XML(解析格式錯誤的 XML)
              1. <small id='G9bu8'></small><noframes id='G9bu8'>

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

                  <tfoot id='G9bu8'></tfoot>

                      <tbody id='G9bu8'></tbody>
                      <i id='G9bu8'><tr id='G9bu8'><dt id='G9bu8'><q id='G9bu8'><span id='G9bu8'><b id='G9bu8'><form id='G9bu8'><ins id='G9bu8'></ins><ul id='G9bu8'></ul><sub id='G9bu8'></sub></form><legend id='G9bu8'></legend><bdo id='G9bu8'><pre id='G9bu8'><center id='G9bu8'></center></pre></bdo></b><th id='G9bu8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G9bu8'><tfoot id='G9bu8'></tfoot><dl id='G9bu8'><fieldset id='G9bu8'></fieldset></dl></div>
                        • <bdo id='G9bu8'></bdo><ul id='G9bu8'></ul>
                          主站蜘蛛池模板: 免费国产一区 | 一级做a爰片性色毛片视频停止 | 日韩欧美综合在线视频 | 欧美视频一区 | 国产精品一区二区日韩 | 日本久久网 | 欧美久久一级特黄毛片 | 国产成人在线一区二区 | 国产日韩久久久久69影院 | 成人av免费在线观看 | 中文字幕欧美日韩一区 | 99视频在线播放 | 日韩视频精品在线 | 欧美精品在欧美一区二区少妇 | 国产精品成人一区二区三区 | 午夜精品久久久久久久久久久久久 | 精精国产视频 | 亚洲高清成人 | 国产精品 亚洲一区 | 99re超碰 | 亚洲精品久 | 国产精品亚洲一区二区三区在线 | 精品亚洲一区二区三区四区五区高 | 国产成人精品999在线观看 | 国产91久久精品一区二区 | 性色av一区 | 精品成人av | 久久精品伊人 | 黄色一级免费观看 | 伊人免费视频二 | 久久亚洲欧美日韩精品专区 | 91伊人 | 国产精品久久久久久久岛一牛影视 | 91精品国产91久久久久久丝袜 | 欧美一区免费在线观看 | 日韩在线免费视频 | 日韩精品视频在线 | 天天操天天摸天天干 | 婷婷开心激情综合五月天 | 夜夜操天天干 | 欧美亚洲激情 |