• <tfoot id='X13fG'></tfoot>

      • <bdo id='X13fG'></bdo><ul id='X13fG'></ul>
    1. <legend id='X13fG'><style id='X13fG'><dir id='X13fG'><q id='X13fG'></q></dir></style></legend>
    2. <i id='X13fG'><tr id='X13fG'><dt id='X13fG'><q id='X13fG'><span id='X13fG'><b id='X13fG'><form id='X13fG'><ins id='X13fG'></ins><ul id='X13fG'></ul><sub id='X13fG'></sub></form><legend id='X13fG'></legend><bdo id='X13fG'><pre id='X13fG'><center id='X13fG'></center></pre></bdo></b><th id='X13fG'></th></span></q></dt></tr></i><div id='X13fG'><tfoot id='X13fG'></tfoot><dl id='X13fG'><fieldset id='X13fG'></fieldset></dl></div>

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

        没有转义反斜杠的 Newtonsoft.Json SerializeObject

        时间:2023-08-24
          <bdo id='J2wPH'></bdo><ul id='J2wPH'></ul>
          <i id='J2wPH'><tr id='J2wPH'><dt id='J2wPH'><q id='J2wPH'><span id='J2wPH'><b id='J2wPH'><form id='J2wPH'><ins id='J2wPH'></ins><ul id='J2wPH'></ul><sub id='J2wPH'></sub></form><legend id='J2wPH'></legend><bdo id='J2wPH'><pre id='J2wPH'><center id='J2wPH'></center></pre></bdo></b><th id='J2wPH'></th></span></q></dt></tr></i><div id='J2wPH'><tfoot id='J2wPH'></tfoot><dl id='J2wPH'><fieldset id='J2wPH'></fieldset></dl></div>
          <legend id='J2wPH'><style id='J2wPH'><dir id='J2wPH'><q id='J2wPH'></q></dir></style></legend>
              <tbody id='J2wPH'></tbody>

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

            • <tfoot id='J2wPH'></tfoot>

                  本文介绍了没有转义反斜杠的 Newtonsoft.Json SerializeObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  给定代码:

                  dynamic foo = new ExpandoObject();
                  foo.Bar = "something";
                  string json = Newtonsoft.Json.JsonConvert.SerializeObject(foo);
                  

                  输出如下:

                  "{"Bar":"something"}"
                  

                  在调试大型 json 文档时,很难阅读 - 使用 Newtonsoft.Json 的内置功能(不是可能破坏事物的正则表达式或黑客)有没有办法使输出成为带有 valie 的字符串:

                  When debugging a large json document it is hard to read - using the built in features of Newtonsoft.Json (not regex or hacks that could break things) is there any way to make the output a string with the valie:

                  {Bar: "something"}
                  

                  推荐答案

                  您在调试器中查看 json 值时看到的是字符串值,您应该在 C# 文件中使用它来获取相同的值.

                  What you see in debugger when looking at the json value is the string value that you should use in a C# file to obtain the same value.

                  确实可以替换

                  dynamic foo = new ExpandoObject();
                  foo.Bar = "something";
                  string json = Newtonsoft.Json.JsonConvert.SerializeObject(foo);
                  

                  string json = "{"Bar":"something"}";
                  

                  不改变程序的行为.

                  因此,要获得不同的值,您应该更改 JsonConvert 有效,但是 JsonConvert 符合 JSON 标准,所以算了!

                  Thus, to obtain a different value, you should change how JsonConvert works, but JsonConvert conforms to the JSON standard, thus forget it!

                  如果您实际上没有序列化 ExpandoObject(或任何其他不受您控制的密封类),您可以使用 DebuggerDisplayAttribute 关于您在 json 中序列化的类型,以定义在调试期间对象的显示方式(在您的代码中,foo 实例).

                  If you are not actually serializing ExpandoObject (nor any other sealed class out of your control), you can use the DebuggerDisplayAttribute on the types that you are serializing in json, to define how the object will be shown during debug (in your code, the foo instance).

                  但字符串就是字符串,VisualStudio 是对的:双引号必须转义.

                  But a string is a string and VisualStudio is right: double-quotes must be escaped.

                  这篇关于没有转义反斜杠的 Newtonsoft.Json SerializeObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我可以选择在运行时关闭 JsonIgnore 属性吗? 下一篇:json.net:为字典键指定转换器

                  相关文章

                  最新文章

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

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

                    <i id='nLJMe'><tr id='nLJMe'><dt id='nLJMe'><q id='nLJMe'><span id='nLJMe'><b id='nLJMe'><form id='nLJMe'><ins id='nLJMe'></ins><ul id='nLJMe'></ul><sub id='nLJMe'></sub></form><legend id='nLJMe'></legend><bdo id='nLJMe'><pre id='nLJMe'><center id='nLJMe'></center></pre></bdo></b><th id='nLJMe'></th></span></q></dt></tr></i><div id='nLJMe'><tfoot id='nLJMe'></tfoot><dl id='nLJMe'><fieldset id='nLJMe'></fieldset></dl></div>
                  1. <legend id='nLJMe'><style id='nLJMe'><dir id='nLJMe'><q id='nLJMe'></q></dir></style></legend>

                    1. <tfoot id='nLJMe'></tfoot>