Skip to main content
 首页 » 编程设计

android之如何使用 retrofit2 将列表发送到 API

2025年04月02日39虾米哥

我使用 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),但我仍然得到同样的错误。

请您参考如下方法:

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

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

并在改造 2 中使用它。

它将生成以下 json:

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