【问题标题】:How to define variable in Android if returned JSON variable has @ sign?如果返回的 JSON 变量有 @ 符号,如何在 Android 中定义变量?
【发布时间】:2018-06-14 22:48:59
【问题描述】:

我正在尝试使用 Retrofit 从 api 读取 json 数据, 但是 json 中的一个变量看起来像这样; @count。 我必须定义相同的变量名来接收数据, 但是这个@ 符号违反了java命名规则。

那么我该如何解决这个问题呢?

【问题讨论】:

    标签: android json api


    【解决方案1】:

    使用count作为变量名和@count作为序列化名称

    @SerializedName("@count")
    public String count;
    

    将 Gson 用于 SerializedName 功能

    implementation 'com.google.code.gson:gson:2.8.5'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-04
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      相关资源
      最近更新 更多