Answer the question
In order to leave comments, you need to log in
How to parse JSON consisting only of objects, not a list?
You need to parse this JSON . My version with the usual map returns null, and I don't want to create separate variables for each object (as the auto-parser suggests to me).
My version:
data class ModelList(
val map: Map<String, String>
)
retrofit = Retrofit.Builder()
.baseUrl("https://openexchangerates.org/")
.addConverterFactory(GsonConverterFactory.create())
.build()
retrofit!!.create(Api::class.java).currencies().enqueue(object : Callback<ModelList>{
override fun onResponse(call: Call<ModelList>, response: Response<ModelList>) {
if (response.body() != null){
// rec_list.apply {
// layoutManager = LinearLayoutManager([email protected])
// }
}else{
showAlert("Error Get: "+ response.code(), response.message(), [email protected])
}
}
override fun onFailure(call: Call<ModelList>, t: Throwable) {
showAlert("Error Get: Fail", t.message.toString(), [email protected])
}
})
interface Api {
@GET("currencies.json")
fun currencies(): Call<ModelList>
}
data class Test(
var AED: String,
var AFN: String,
var ALL: String,
var AMD: String,
var ANG: String,
var AOA: String,
var ARS: String,
var AUD: String,
var AWG: String,
var AZN: String,
var BAM: String,
var BBD: String,
var BDT: String,
var BGN: String,
var BHD: String,
var BIF: String,
var BMD: String,
var BND: String,
var BOB: String,
var BRL: String,
var BSD: String,
var BTC: String,
var BTN: String,
var BWP: String,
var BYN: String,
var BZD: String,
var CAD: String
.......
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question