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

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

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

      • <bdo id='Y1lOH'></bdo><ul id='Y1lOH'></ul>

        <legend id='Y1lOH'><style id='Y1lOH'><dir id='Y1lOH'><q id='Y1lOH'></q></dir></style></legend>
        <tfoot id='Y1lOH'></tfoot>

        JSON.NET Parser *似乎*對我的對象進行雙重序列化

        JSON.NET Parser *seems* to be double serializing my objects(JSON.NET Parser *似乎*對我的對象進行雙重序列化)
        <i id='vl5TS'><tr id='vl5TS'><dt id='vl5TS'><q id='vl5TS'><span id='vl5TS'><b id='vl5TS'><form id='vl5TS'><ins id='vl5TS'></ins><ul id='vl5TS'></ul><sub id='vl5TS'></sub></form><legend id='vl5TS'></legend><bdo id='vl5TS'><pre id='vl5TS'><center id='vl5TS'></center></pre></bdo></b><th id='vl5TS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vl5TS'><tfoot id='vl5TS'></tfoot><dl id='vl5TS'><fieldset id='vl5TS'></fieldset></dl></div>
          <legend id='vl5TS'><style id='vl5TS'><dir id='vl5TS'><q id='vl5TS'></q></dir></style></legend><tfoot id='vl5TS'></tfoot>

                <tbody id='vl5TS'></tbody>

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

              • <bdo id='vl5TS'></bdo><ul id='vl5TS'></ul>
                  本文介紹了JSON.NET Parser *似乎*對我的對象進行雙重序列化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的問題是這樣的:

                  這是從我的 WebAPI 控制器發回的響應.

                  This is the response being sent back from my WebAPI controller.

                  "[
                     [
                        {"id":"identifier"},
                        {"name":"foobar"}
                     ]
                  ]"
                  

                  請注意,響應包含在引號中,并且所有嵌入的引號都被轉義了.這顯然是個問題.我可以向 JSON.NET 序列化程序提供任何設置來防止這種情況發生嗎?

                  Notice that the response is wrapped in quotations and all of the embedded quotations are escaped. This is obviously a problem. Are there any settings I can provide to the JSON.NET Serializer to prevent this from occurring?

                  正如 p.s.w.g 在他的回復中猜測的那樣,我使用的是 JSON.NET 的

                  As p.s.w.g guessed in his response, I was using JSON.NET's

                  JsonConvert.SerializeObject(instance)
                  

                  執行我的序列化.

                  我這樣做是因為在構建自定義轉換器時,我已將它們包含在我的 WepApiConfig 中的 JsonConvert.DefaultSettings 中(我顯然認為這不會成為問題)

                  I did this because as I was building out my custom Converters, I had included them in the JsonConvert.DefaultSettings within my WepApiConfig (and I obviously thought this would not be a problem)

                  我之前曾嘗試將我的 HttpGets 的返回類型交換為我的對象類型",并且響應是我的對象的 ToString() 方法的 json 表示...這讓我知道序列化沒有通過我的轉換器.

                  I had previously tried to swap the return type of my HttpGets to "my object type" and the response was a json representation of my object's ToString() method...which let me know that serialization was not passing through my converters.

                  將我的 HttpGets 的返回類型從字符串更改為我的對象類型"并將這些轉換器直接插入 WebAPi 的默認 HttpConfiguration 就可以了.

                  Changing the return type of my HttpGets from string to "my object type" and plugging those converters straight into WebAPi's default HttpConfiguration did the trick.

                  config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new FooConverter());
                  config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new BarConverter());
                  

                  簡單易懂.

                  推薦答案

                  你可能有這樣的情況:

                  public string GetFoobars()
                  {
                      var foobars = ...
                      return JsonConvert.SerializeObject(foobars);
                  }
                  

                  在這種情況下,您將使用 Json.NET 將對象序列化為字符串,然后通過將結果作為字符串返回,API 控制器會將字符串序列化為 JavaScript 字符串文字——這將導致字符串被包裝在雙引號中并導致字符串中的任何其他特殊字符用反斜杠轉義.

                  In this case, you're serializing the object into string with Json.NET, then by returning the result as a string, the API controller will serialize the string as a JavaScript string literal—which will cause the string to be wrapped in double quotes and cause any other special characters inside the string to escaped with a backslash.

                  解決方案是簡單地自己返回對象:

                  The solution is to simply return the objects by themselves:

                  public IEnumerable<Foobar> GetFoobars()
                  {
                      var foobars = ...
                      return foobars;
                  }
                  

                  這將導致 API 控制器使用其默認設置序列化對象,這意味著它將根據從客戶端傳入的參數將結果序列化為 XML 或 JSON.

                  This will cause the API controller to serialize the objects using it's default settings, meaning it will serialize the result as XML or JSON depending on the parameters passed in from the client.

                  進一步閱讀

                  • ASP.NET Web 中的 JSON 和 XML 序列化API

                  這篇關于JSON.NET Parser *似乎*對我的對象進行雙重序列化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                      • <tfoot id='ZORpT'></tfoot>
                      • <legend id='ZORpT'><style id='ZORpT'><dir id='ZORpT'><q id='ZORpT'></q></dir></style></legend>

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

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

                            <tbody id='ZORpT'></tbody>
                            <bdo id='ZORpT'></bdo><ul id='ZORpT'></ul>

                            主站蜘蛛池模板: 亚洲精品综合一区二区 | 天天操网 | 日韩免费电影 | 黄色av网站免费看 | 久久久久久久久久久国产 | 黄视频在线网站 | 国产99久久久国产精品 | 一区二区三区四区视频 | 亚洲一区二区久久 | 91在线视频一区 | 欧美理伦片在线播放 | 91在线观看视频 | 一区二区三区韩国 | 91国自产| 亚洲性人人天天夜夜摸 | 免费国产一区二区 | 91亚洲精| 人人干免费 | 天天操网 | 91在线观看 | 中文字幕一区在线观看视频 | 偷拍亚洲色图 | 国产精品一区二 | av在线免费观看网站 | 亚洲免费毛片 | 国产亚洲欧美在线 | 欧美一区二区三区视频 | 亚洲狠狠 | 久热中文字幕 | 国产精品五区 | 久国产 | 成人午夜在线 | 国产乱码久久久久久 | 婷婷色国产偷v国产偷v小说 | 99久久精品免费看国产免费软件 | 日韩一区二区久久 | 伊人网伊人网 | 日日欧美 | 久久精品色欧美aⅴ一区二区 | 亚洲视频在线一区 | 精品一区二区在线观看 |