簡體   English   中英

使用 Retrofit Android 解析響應中的 JSON 數組

[英]Parse JSON Array in Response using Retrofit Android

使用 Retrofit 解析以下 JSON 響應。

提前致謝。

[
{"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
},
]

您可以使用 Retrofit2 Converter.Factory -

如果 Java http://www.jsonschema2pojo.org/如果使用 kotlin https://www.json2kotlin.com/,則使用此站點將 json 轉換為 pojo

並像這樣使用它,實施后您將獲得 Object,因此無需解析

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

    ):
    Observable<yout_model_generated_from_above_link>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM