【问题标题】:Gson parses to LinkedTreeMap when serializing ArrayList of Generic Type [duplicate]序列化通用类型的ArrayList时,Gson解析为LinkedTreeMap [重复]
【发布时间】:2018-06-26 04:08:31
【问题描述】:

我有这个 JSON 字符串:

[  
   {  
      "k":"number",
      "v":"055 543 8679\n"
   },
   {  
      "k":"hours",
      "v":"8:00AM - 9:00PM"
   }
]

我正在尝试使用 Gson 解析它:

    val customFields = Gson().fromJson(food.customFields, ArrayList<CustomField>()::class.java)

但不知何故,当我以断点模式查看时,它被解析为LinkedTreeMap

【问题讨论】:

    标签: android json arraylist kotlin gson


    【解决方案1】:

    试试这个val customFields = new Gson().fromJson(food.customFields, CustomField.class);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多