英文:
how to post array of generic objects in retrofit
问题
{
"items": [
{
"variant": {
"id": 48,
"quantity": "1"
},
"custom_form_data": {
"features": {
"delivery_email": "haw@ogloba.com",
"delivery_mobile": "+886970639636"
},
"customer_info": "TEST Han Customer Info"
}
}
]
}
这是请求的调用:
items = arrayOf(
Variant(id = 48, quantity = "1"),
CustomFormData(features = Features("haw@ogloba.com", "+886970639636"), customerInfo = "inof")
)
英文:
I Have this JSON , needed it to post on the server , the problem how we send array of generic objects
"items": [
{
"variant": {
"id": 48,
"quantity": "1"
},
"custom_form_data": {
"features": {
"delivery_email": "haw@ogloba.com",
"delivery_mobile": "+886970639636"
},
"customer_info": "TEST Han Customer Info"
}
}
],
this is the call
items = arrayOf(
Variant(id = 48, quantity = "1"),
CustomFormData(features = Features("haw@ogloba.com", "+886970639636") ,customerInfo = "inof")
),
答案1
得分: 1
定义一个适用于该格式的数据类,类似于这样:
data class Item(
val variant: Variant,
val custom_form_data: CustomFormData
)
然后在你的 Retrofit ApiService 接口定义中:
interface ApiService {
@POST("url")
fun methodName(): List<Item>
}
英文:
Define a data class for that format, something like this:
data class Item (
val variant: Variant,
val custom_form_data: CustomFormData
)
And then in your retrofit ApiService interface definition:
interface ApiService {
@POST('url')
fun methodName(): List<Item>
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论