<tfoot id='tK81E'></tfoot>

  • <legend id='tK81E'><style id='tK81E'><dir id='tK81E'><q id='tK81E'></q></dir></style></legend>
    • <bdo id='tK81E'></bdo><ul id='tK81E'></ul>

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

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

        使用 JSON.net 获取 JToken 的名称/密钥

        Getting the name / key of a JToken with JSON.net(使用 JSON.net 获取 JToken 的名称/密钥)
          • <i id='VxVRh'><tr id='VxVRh'><dt id='VxVRh'><q id='VxVRh'><span id='VxVRh'><b id='VxVRh'><form id='VxVRh'><ins id='VxVRh'></ins><ul id='VxVRh'></ul><sub id='VxVRh'></sub></form><legend id='VxVRh'></legend><bdo id='VxVRh'><pre id='VxVRh'><center id='VxVRh'></center></pre></bdo></b><th id='VxVRh'></th></span></q></dt></tr></i><div id='VxVRh'><tfoot id='VxVRh'></tfoot><dl id='VxVRh'><fieldset id='VxVRh'></fieldset></dl></div>
              <tbody id='VxVRh'></tbody>

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

                  <tfoot id='VxVRh'></tfoot>

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

                  <legend id='VxVRh'><style id='VxVRh'><dir id='VxVRh'><q id='VxVRh'></q></dir></style></legend>
                  本文介绍了使用 JSON.net 获取 JToken 的名称/密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一些像这样的 JSON

                  I have some JSON that looks like this

                  [
                    {
                      "MobileSiteContent": {
                        "Culture": "en_au",
                        "Key": [
                          "NameOfKey1"
                        ]
                      }
                    },
                    {
                      "PageContent": {
                        "Culture": "en_au",
                        "Page": [
                          "about-us/"
                        ]
                      }
                    }
                  ]
                  

                  我将其解析为 JArray:

                  I parse this as a JArray:

                  var array = JArray.Parse(json);
                  

                  然后,我循环遍历数组:

                  Then, I loop over the array:

                  foreach (var content in array)
                  {
                  
                  }
                  

                  content 是一个 JToken

                  如何检索每个项目的名称"或密钥"?

                  How can I retrieve the "name" or "key" of each item?

                  例如,MobileSiteContent"或PageContent"

                  For example, "MobileSiteContent" or "PageContent"

                  推荐答案

                  JTokenJObject, JArray, 的基类>JPropertyJValue 等.您可以使用 Children<T>() 方法获取某个 JToken 的子代的过滤列表类型,例如 JObject.每个 JObject 都有一个 JProperty 对象的集合,可以通过 Properties() 方法访问这些对象.对于每个 JProperty,您可以获得它的 Name.(当然你也可以根据需要获取Value,也就是另一个JToken.)

                  JToken is the base class for JObject, JArray, JProperty, JValue, etc. You can use the Children<T>() method to get a filtered list of a JToken's children that are of a certain type, for example JObject. Each JObject has a collection of JProperty objects, which can be accessed via the Properties() method. For each JProperty, you can get its Name. (Of course you can also get the Value if desired, which is another JToken.)

                  综合起来我们有:

                  JArray array = JArray.Parse(json);
                  
                  foreach (JObject content in array.Children<JObject>())
                  {
                      foreach (JProperty prop in content.Properties())
                      {
                          Console.WriteLine(prop.Name);
                      }
                  }
                  

                  输出:

                  MobileSiteContent
                  PageContent
                  

                  这篇关于使用 JSON.net 获取 JToken 的名称/密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 自定义合约序列化和集合)

                        <small id='7QkwZ'></small><noframes id='7QkwZ'>

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

                          • <bdo id='7QkwZ'></bdo><ul id='7QkwZ'></ul>