如何使用 retrofit2 将列表发送到 API
How to send an list to API using retrofit2
我使用 EVE
开发了一个 API。
这是架构:
central_schema = {
'name': {
'type': 'string',
'required': True,
},
'id_account': {
'type': 'list',
}
}
我正在尝试使用 retrofit 2
发送列表。我使用 POSTMAN
尝试了 API。每次我收到这样的回复:
id account "must be of list type"
我使用了很多类型的请求(PATCH
、POST
、PUT
),但我仍然得到同样的错误。
您可以像下面这样创建模型 class:
public class Model{
public String name;
public List<String> id_account;
}
并在改造 2 中使用它。
它将产生以下json:
{
"name": "xyz",
"id_account" : [
"1",
"2"
]
}
我使用 EVE
开发了一个 API。
这是架构:
central_schema = {
'name': {
'type': 'string',
'required': True,
},
'id_account': {
'type': 'list',
}
}
我正在尝试使用 retrofit 2
发送列表。我使用 POSTMAN
尝试了 API。每次我收到这样的回复:
id account "must be of list type"
我使用了很多类型的请求(PATCH
、POST
、PUT
),但我仍然得到同样的错误。
您可以像下面这样创建模型 class:
public class Model{
public String name;
public List<String> id_account;
}
并在改造 2 中使用它。
它将产生以下json:
{
"name": "xyz",
"id_account" : [
"1",
"2"
]
}