<bdo id='9OK4f'></bdo><ul id='9OK4f'></ul>

    <tfoot id='9OK4f'></tfoot>
    1. <small id='9OK4f'></small><noframes id='9OK4f'>

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

      1. 使用 Json.net 反序列化 JSON 对象数组

        时间:2023-08-23

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

              <bdo id='vfPcd'></bdo><ul id='vfPcd'></ul>
                  <tbody id='vfPcd'></tbody>

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

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

                  问题描述

                  我正在尝试使用一个 API,该 API 使用以下示例结构来返回其返回的 json

                  I am attempt to use an API that use the follow example structure for their returned json

                  [
                     {
                        "customer":{
                           "first_name":"Test",
                           "last_name":"Account",
                           "email":"test1@example.com",
                           "organization":"",
                           "reference":null,
                           "id":3545134,
                           "created_at":"2013-08-06T15:51:15-04:00",
                           "updated_at":"2013-08-06T15:51:15-04:00",
                           "address":"",
                           "address_2":"",
                           "city":"",
                           "state":"",
                           "zip":"",
                           "country":"",
                           "phone":""
                        }
                     },
                     {
                        "customer":{
                           "first_name":"Test",
                           "last_name":"Account2",
                           "email":"test2@example.com",
                           "organization":"",
                           "reference":null,
                           "id":3570462,
                           "created_at":"2013-08-12T11:54:58-04:00",
                           "updated_at":"2013-08-12T11:54:58-04:00",
                           "address":"",
                           "address_2":"",
                           "city":"",
                           "state":"",
                           "zip":"",
                           "country":"",
                           "phone":""
                        }
                     }
                  ]
                  

                  JSON.net 可以很好地使用类似以下结构的东西

                  JSON.net would work great with something like the following structure

                  {
                      "customer": {
                          ["field1" : "value", etc...],
                          ["field1" : "value", etc...],
                      }
                  }
                  

                  但我不知道如何让它对提供的结构感到满意.

                  But I can not figure out how to get it to be happy with the provided structure.

                  使用默认的 JsonConvert.DeserializeObject(content) 得到正确数量的客户,但所有数据为空.

                  Using the default JsonConvert.DeserializeObject(content) results the correct number of Customer but all of the data is null.

                  对 CustomerList(如下)执行操作会导致无法反序列化当前 JSON 数组"异常

                  Doing something a CustomerList (below) results in a "Cannot deserialize the current JSON array" exception

                  public class CustomerList
                  {
                      public List<Customer> customer { get; set; }
                  }
                  

                  想法?

                  推荐答案

                  您可以创建一个新模型来反序列化您的 JSON CustomerJson:

                  You can create a new model to Deserialize your JSON CustomerJson:

                      public class CustomerJson
                      {
                          [JsonProperty("customer")]
                          public Customer Customer { get; set; }
                      }
                  
                      public class Customer
                      {
                          [JsonProperty("first_name")]
                          public string Firstname { get; set; }
                  
                          [JsonProperty("last_name")]
                          public string Lastname { get; set; }
                  
                          ...
                      }
                  

                  您可以轻松地反序列化您的 JSON:

                  And you can deserialize your JSON easily:

                  JsonConvert.DeserializeObject<List<CustomerJson>>(json);
                  

                  文档:序列化和反序列化 JSON

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

                  上一篇:如何使用 JSON.NET 确保字符串是有效的 JSON 下一篇:有时是数组有时是对象时反序列化JSON

                  相关文章

                  最新文章

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

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

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