简体   繁体   中英

Parse JSON Array in Response using Retrofit Android

Parse the below JSON Response using Retrofit.

Thanks in advance.

[
{"borrowerId":6,
"borrowerName":"archanaB",
"loanId":"LN3",
"numbersOfEmisPaid":2,
"profit":300.0,
"disburmentAmount":5000.0,
"emisReceived":1967.0
},
{
"borrowerId":6,
"borrowerName":"archanaB",
"loanId":"LN14",
"numbersOfEmisPaid":1,
"profit":150.0,
"disburmentAmount":5000.0,
"emisReceived":983.0
},{
"borrowerId":2,
"borrowerName":"NarendraB",
"loanId":"LN12",
"numbersOfEmisPaid":6,
"profit":175.0,
"disburmentAmount":35000.0,
"emisReceived":36050.0
},
{
"borrowerId":6,
"borrowerName":"archanaB",
"loanId":"LN4",
"numbersOfEmisPaid":18,
"profit":133.0,
"disburmentAmount":5000.0,
"emisReceived":344.0
},
]

You can use one of the Retrofit2 Converter.Factory -

Convert json to pojo using this site if Java http://www.jsonschema2pojo.org/ if using kotlin https://www.json2kotlin.com/

and use it like that, after implementing you will get Object so no need to parse

 @POST(your_api)
    fun details(
        @QueryName id: Int

    ):
    Observable<yout_model_generated_from_above_link>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM