我正在通过Kotlin开发一个Android应用程序。该应用程序使用Retrofit2处理HTTP请求。我一遍又一遍地使用Retrofit2,但我不知道如何解决这个场景。
我想使用一个API,它需要像query1、query2等查询(接近100个可用值)。
例如:
When I send a request via "query1" the response object has coordinates: List<List<List<Double>>>
When I send a request via "query2" the response object has coordinates: List<List<Double>>
When I send a request via "query3" the response object has coordinates: List<List<List<List<Double>>>>
When I send a request via "query4" the response object has coordinates: List<List<Double>>
我不知道API如何返回内部列表计数。顺便说一下,对象中只有一个坐标。
JSON格式的响应对象
[
{
"key-1": "value-1",
"key-2": "value-2",
"key-3": "value-3",
"key-4": {
"inner-key": [
[
[
1.0,
1.0
],
[
1.0,
1.0
]
]
]
}
},
{
"key-1": "value-1",
"key-2": "value-2",
"key-3": "value-3",
"key-4": {
"inner-key": [
[
[
[
1.0,
1.0
],
[
1.0,
1.0
]
],
[
[
1.0,
1.0
],
[
1.0,
1.0
]
]
]
]
}
}
]
这是我的数据类。但我不知道如何定义"key4“对象。
data class Response(
val key1: String? = null,
val key2: String? = null,
val key3: String? = null,
val key4: key4? = null,
)
data class key4(
//How should I define the "inner-key" object
)
任何建议都会有帮助。
发布于 2021-04-13 03:36:07
解决方案:
我尝试了几种解决办法。我不知道它是完美的解决方案,但有我的解决方案
在我的问题上有我的数据类,它的名字是key4。
data class key4(
val inner-key: List<Any>? = null
)
我还投了一个内键,比如:
val temp = response?.key4?.inner-key as List<List<Double>>?
或
val temp = response?.key4?.inner-key as List<List<List<Double>>>?
https://stackoverflow.com/questions/66950333
复制