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

      <tfoot id='0zjCy'></tfoot>

      1. <legend id='0zjCy'><style id='0zjCy'><dir id='0zjCy'><q id='0zjCy'></q></dir></style></legend>

      2. <small id='0zjCy'></small><noframes id='0zjCy'>

        使用 Json.Net 解析 JSON 数组

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

          <legend id='7hS5P'><style id='7hS5P'><dir id='7hS5P'><q id='7hS5P'></q></dir></style></legend>
            <tbody id='7hS5P'></tbody>

          • <small id='7hS5P'></small><noframes id='7hS5P'>

            <tfoot id='7hS5P'></tfoot>
            • <bdo id='7hS5P'></bdo><ul id='7hS5P'></ul>
                  本文介绍了使用 Json.Net 解析 JSON 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Json.Net 来解析一个数组.我要做的是将名称/值对从数组中提取出来,并在解析 JObject 时将它们分配给特定的变量.

                  I'm working with Json.Net to parse an array. What I'm trying to do is to pull the name/value pairs out of the array and assign them to specific variables while parsing the JObject.

                  这是我在数组中得到的:

                  Here's what I've got in the array:

                  [
                    {
                      "General": "At this time we do not have any frequent support requests."
                    },
                    {
                      "Support": "For support inquires, please see our support page."
                    }
                  ]
                  

                  这就是我在 C# 中得到的:

                  And here's what I've got in the C#:

                  WebRequest objRequest = HttpWebRequest.Create(dest);
                  WebResponse objResponse = objRequest.GetResponse();
                  using (StreamReader reader = new StreamReader(objResponse.GetResponseStream()))
                  {
                      string json = reader.ReadToEnd();
                      JArray a = JArray.Parse(json);
                  
                      //Here's where I'm stumped
                  
                  }
                  

                  我对 JSON 和 Json.Net 还很陌生,所以它可能是其他人的基本解决方案.我基本上只需要在 foreach 循环中分配名称/值对,以便我可以在前端输出数据.有没有人这样做过?

                  I'm fairly new to JSON and Json.Net, so it might be a basic solution for someone else. I basically just need to assign the name/value pairs in a foreach loop so that I can output the data on the front-end. Has anyone done this before?

                  推荐答案

                  你可以像这样获取数据值:

                  You can get at the data values like this:

                  string json = @"
                  [ 
                      { ""General"" : ""At this time we do not have any frequent support requests."" },
                      { ""Support"" : ""For support inquires, please see our support page."" }
                  ]";
                  
                  JArray a = JArray.Parse(json);
                  
                  foreach (JObject o in a.Children<JObject>())
                  {
                      foreach (JProperty p in o.Properties())
                      {
                          string name = p.Name;
                          string value = (string)p.Value;
                          Console.WriteLine(name + " -- " + value);
                      }
                  }
                  

                  小提琴:https://dotnetfiddle.net/uox4Vt

                  这篇关于使用 Json.Net 解析 JSON 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:确保 .NET 中的 json 键是小写的 下一篇:序列化字典时保留大小写

                  相关文章

                  最新文章

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

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

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

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