我有希望作爲輸入的運動類型的API:Android的改造 - 傳遞對象的列表作爲關聯數組
exercises[0][duration]=10
exercises[0][type]=jump
exercises[1][duration]=20
exercises[1][type]=roll
在Android方面,我一直在使用我的改造API類建。
如何將我的List<Exercise>
傳遞給API方法以獲取上述參數。
目前嘗試:
@FormUrlEncoded
@POST("api/v1/patient/{id}/workout")
fun addPatientWorkout(@Path("id") id: Long,
@Field("title") title: String,
@Field("exercises[]") exercises: List<Map<String,String>>)
: Single<Response<Workout>>
但是,這並沒有給我的期望。相反:
exercises[]={duration:10, type=jump}&exercises[]={duration:20, type=roll}
我會通過一個簡單的 「演習」
如下您可以將其轉換以JSON格式列出,而不是地圖。一旦你將它作爲JSON檢索,這種格式看起來很容易處理數組:「Exercises」:[{「duration」...},{...}] – Ricardo
我無法控制API。我必須使用這種格式。 –
請檢查此答案https://stackoverflow.com/questions/37698715/how-to-send-arrays-lists-with-retrofit –