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

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

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

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

        JSON.NET 如何删除节点

        时间:2023-05-22
          <bdo id='f2xhh'></bdo><ul id='f2xhh'></ul>
          <tfoot id='f2xhh'></tfoot>

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

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

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

                  本文介绍了JSON.NET 如何删除节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个像下面这样的 json:

                  I have a json like the following:

                  {
                    "d": {
                      "results": [
                        {
                          "__metadata": {
                          },
                          "prop1": "value1",
                          "prop2": "value2",
                          "__some": "value"
                        },
                        {
                          "__metadata": {
                          },
                          "prop3": "value1",
                          "prop4": "value2",
                          "__some": "value"
                        },
                      ]
                    }
                  }
                  

                  我只想将此 JSON 转换为不同的 JSON.我想从 JSON 中去掉_metadata"和_some"节点.我正在使用 JSON.NET.

                  I just want to transform this JSON into a different JSON. I want to strip out the "_metadata" and "_some" nodes from the JSON. I'm using JSON.NET.

                  推荐答案

                  我刚刚反序列化为 JObject 并递归地循环遍历它以删除不需要的字段.感兴趣的朋友可以看看这里的功能.

                  I just ended up deserializing to JObject and recursively looping through that to remove unwanted fields. Here's the function for those interested.

                  private void removeFields(JToken token, string[] fields)
                  {
                      JContainer container = token as JContainer;
                      if (container == null) return;
                  
                      List<JToken> removeList = new List<JToken>();
                      foreach (JToken el in container.Children())
                      {
                          JProperty p = el as JProperty;
                          if (p != null && fields.Contains(p.Name))
                          {
                              removeList.Add(el);
                          }
                          removeFields(el, fields);
                      }
                  
                      foreach (JToken el in removeList)
                      {
                          el.Remove();
                      }
                  }
                  

                  这篇关于JSON.NET 如何删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Newtonsoft.Json 将对象序列化为带有类型信息的 json? 下一篇:Json.NET 不区分大小写的属性反序列化

                  相关文章

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

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

                  1. <tfoot id='HmXCF'></tfoot><legend id='HmXCF'><style id='HmXCF'><dir id='HmXCF'><q id='HmXCF'></q></dir></style></legend>

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