• <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 如何删除节点

        JSON.NET how to remove nodes(JSON.NET 如何删除节点)
          <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 如何删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

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

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

                        • <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>