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

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

        <tfoot id='VWlZ4'></tfoot>

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

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

        如何反序列化包含无效字段名称的 JSON 对象

        时间:2023-08-22
          <bdo id='0WV7B'></bdo><ul id='0WV7B'></ul>
        • <i id='0WV7B'><tr id='0WV7B'><dt id='0WV7B'><q id='0WV7B'><span id='0WV7B'><b id='0WV7B'><form id='0WV7B'><ins id='0WV7B'></ins><ul id='0WV7B'></ul><sub id='0WV7B'></sub></form><legend id='0WV7B'></legend><bdo id='0WV7B'><pre id='0WV7B'><center id='0WV7B'></center></pre></bdo></b><th id='0WV7B'></th></span></q></dt></tr></i><div id='0WV7B'><tfoot id='0WV7B'></tfoot><dl id='0WV7B'><fieldset id='0WV7B'></fieldset></dl></div>
            <tbody id='0WV7B'></tbody>
        • <legend id='0WV7B'><style id='0WV7B'><dir id='0WV7B'><q id='0WV7B'></q></dir></style></legend>

            • <tfoot id='0WV7B'></tfoot>

                <small id='0WV7B'></small><noframes id='0WV7B'>

                  本文介绍了如何反序列化包含无效字段名称的 JSON 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 JSON 请求,其结构如下:

                  I have a JSON request which has follwing structure:

                  "formats":  {
                          "flash_embed": "http://a3.vikiassets.com/assets/vikiplayer-922746a667cfd38137a7e45df6ba1b95.swf?auto_play=true&language_codes=en&media_id=74965&partner=16&source=api_v3",
                          "m3u8": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965/ios.m3u8",
                          "res-150p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_mp4cell_150.mp4",
                          "res-240p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_240p.mp4",
                          "res-270p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_270p.mp4",
                          "res-360p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_360p.mp4",
                          "res-480p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_480p.mp4",
                          "res-720p": "http://wpc.354a.edgecastcdn.net/00354A/videos/encoded/74965_720p.mp4"
                        }
                      }
                  

                  现在 res-150p,在 C# 中表示无效名称,如果我给它取另一个名称,那么在进行理想化时我没有得到任何值,这在 res-150p 中为 null.

                  Now res-150p, says invalid name in C# and if I give another name to it then while desiralizing I am not getting any values, that is null inside res-150p.

                  [可序列化]MoviesListRootObject 是包含 Response 然后 Response 包含 Formats

                  [Serializable] MoviesListRootObject is the root Object which Contains Response and then Response Contains Formats

                  public class MoviesListRootObject
                  {
                      public int count { get; set; }
                      public Pagination pagination { get; set; }
                      public List<Response> response { get; set; }
                  }
                  
                  [Serializable]
                  public class Response
                  {
                      public int id { get; set; }
                      public int channel_id { get; set; }
                      public string title { get; set; }
                      public string title_language { get; set; }
                      public string description { get; set; }
                      public string description_language { get; set; }
                      public string created_at { get; set; }
                      public string uri { get; set; }
                      public string web_uri { get; set; }
                      public List<object> genres { get; set; }
                      public string origin_country { get; set; }
                      public string image { get; set; }
                      public Subtitles subtitles { get; set; }
                      public Formats formats { get; set; }
                  }
                  
                  [Serializable]
                  public class Formats
                  {
                      public string flash_embed { get; set; }
                      public string m3u8 { get; set; }
                      public string __invalid_name__res150p { get; set; }
                      public string __invalid_name__res240p { get; set; }
                      public string __invalid_name__res270p { get; set; }
                      public string __invalid_name__res360p { get; set; }
                      public string __invalid_name__res480p { get; set; }
                      public string __invalid_name__res720p { get; set; }
                      public string __invalid_name__flv480p { get; set; }
                      public string __invalid_name__flv360p { get; set; }
                      public string __invalid_name__flv270p { get; set; }
                      public string __invalid_name__flvvp6360p { get; set; }
                      public string __invalid_name__flvvp6270p { get; set; }
                  }
                  

                  推荐答案

                  你必须用 JsonProperty 属性来装饰你的 Formats 属性,告诉它如果名字在哪里不完全匹配:

                  You have to decorate your Formats properties with JsonProperty attributes to tell it what goes where if the name does not exactly match:

                  partial class Formats
                  {
                      [JsonProperty("res-150p")]
                      public string __invalid_name__res150p {get; set;}
                  }
                  

                  另请参阅 使用 JsonConvert.DeserializeObject 来将 Json 反序列化为 C# POCO 类

                  这篇关于如何反序列化包含无效字段名称的 JSON 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:反序列化DataTable后DateTime列类型变为String类型 下一篇:如何强制 Json.net 中的最小小数位数?

                  相关文章

                  最新文章

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

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

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

                    2. <tfoot id='trziD'></tfoot>

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