我无法用 gson 解析 JSON

I can't parse a JSON with gson

我有这部分 json POKEAPI get pokemons/sprite/version/

来自 POKEAPI,问题出在 kotlin 中我不能使用“-”来创建变量,例如:“var myvar-i = 0”我需要创建与 JSON 用于 GSON 映射和我需要的 JSON 中的精灵是这样的

第i代 第二代 等..

在 kotlin 中,我无法使用“-”创建变量 enter image description here

谁能帮帮我,我怎样才能在 kotlin 中映射这些信息?

您可以使用注释@SerializedName

在你的情况下它会是这样的:

class Versions {
    @SerializedName("generation-i")
    var generation1: Generationgame? = null
   ...
}

有关注释的更多信息,请参阅 the docs