【问题标题】:How to send an list to API using retrofit2如何使用 Retrofit2 将列表发送到 API
【发布时间】:2016-05-16 00:02:42
【问题描述】:

我使用 EVE 开发了一个 API。

这是架构:

central_schema = {
    'name': {
        'type': 'string',
        'required': True,
    },
    'id_account': {
        'type': 'list',
    }
}

我正在尝试使用retrofit 2 发送列表。我使用POSTMAN 尝试了 API。每次收到这样的回复:

id account "must be of list type"

我使用了多种类型的请求(PATCHPOSTPUT),但我仍然遇到同样的错误。

【问题讨论】:

  • 我不知道retorfit2,但你能发布你的请求格式吗?列表格式必须类似于 "id_account" : ["1", "2"]。

标签: android python api retrofit eve


【解决方案1】:

您可以像下面这样创建模型类:

public class Model{
    public String name;
    public List<String> id_account;
}

并在改造 2 中使用它。

它会产生下面的json:

{
    "name": "xyz",
    "id_account" : [
         "1",
         "2"
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2014-04-20
    • 2018-09-13
    • 1970-01-01
    相关资源
    最近更新 更多