【问题标题】:Nested Json Parsing to c#(Console Application) [closed]嵌套 Json 解析到 c#(控制台应用程序)[关闭]
【发布时间】:2021-10-31 19:27:22
【问题描述】:

我需要将 Json 解析成 C#(控制台应用程序),还需要在数据表中查看解析后的数据。

据我所知,我已尝试生成类。

代码:

   {
   "RLC": [
     {
       "PAR": ""
     },
     {
       "PAR": ""
     },
     {
       "PAR": ""
     }
   ],
   "PR":

请帮忙。

【问题讨论】:

  • 好的。你在这里面临什么问题?你都尝试了些什么?你做了什么研究?
  • 我推荐使用this answerthis answer
  • 我还需要在数据表中获取这些,所以如何添加?@Llama
  • 我不明白您拥有的数据如何在表格中表示。有多种方法可以将 JSON 反序列化为 DataTable,但您有数组属性。

标签: c# json parsing datatable


【解决方案1】:

你可以使用下面的c#类来序列化json

// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
    public class RecordLocator
    {
        public string PNR { get; set; }
    }

    public class PNRAmount
    {
        public string BalanceDue { get; set; }
        public string AuthorizedBalanceDue { get; set; }
        public string SegmentCount { get; set; }
        public string PassiveSegmentCount { get; set; }
        public string TotalCost { get; set; }
        public string PointsBalanceDue { get; set; }
        public string TotalPointCost { get; set; }
        public List<object> AlternateCurrencyCode { get; set; }
        public string AlternateCurrencyBalanceDue { get; set; }
    }

    public class Root
    {
        public List<RecordLocator> RecordLocator { get; set; }
        public PNRAmount PNRAmount { get; set; }
    }

【讨论】:

  • 我还需要在数据表中获取这些,所以如何添加?@GowriPranithBayyana
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-09
  • 2015-10-19
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多