Home > database >  How to use json in Android with Retrofit
How to use json in Android with Retrofit

Time:11-10

In my application I want get some data from server and show this into list (recyclerview)!
I receive data from server such as below :

 "data": {
      "id": 1812286134,
      "Cr": "85",
      "BUN": "87",
      "ALP": "75",
      "ALT": "6",
      "AST": "6",
      "Chol": "55",
      "HDL": "545",
      "LDL": "45",
      "TG": "4",
      "created_at": "2022-10-30 16:05:50",
      "updated_at": "2022-10-30 16:05:50"
    }

UPDATE :
This data may update in some time, added new items or remove items by admins

I should show all of this items into recyclerview.
I know in above json data should list but has object.
But backend developer tells me convert all of this data to list with key value!
My question is can I convert this data to list and use all of items into list ?
How can I it?

CodePudding user response:

Try to use Map<String,String> in your Response or whatever you used.

It will be something like this.

@GET
fun getCurrency():Response<DataResponse>

data class DataResponse(
val currencies:Map<String,String>
)
  • Related