如何使用Retrofit传递字典数组

时间:2017-05-30 17:53:06

标签: android retrofit2

我正在使用iOS应用的Android端口,我在将参数传递给API时遇到了一些问题。在iOS上我们使用了Alamofire,我们传递的参数在iOS端看起来像这样

["topics": [["slug": "health", "importance": 1], ["slug": "environment", "importance": 2], ["slug": "technology", "importance": 0]...]

但我似乎无法使用Retrofit 2在Android端复制相同的行为。我尝试为每个集合创建一个Hashmap,然后将所有哈希映射添加到数组列表并传递但是它没有&当我通过它时格式正确(如Request {method = POST,url = / api / v1 / topics?topics = {slug%3Dhealth,%20importance%3D1}& beliefs = {slug%3Denvironment,%20importance %3D1})。这是我到目前为止所得到的

HashMap<String, Object> healthMap = new HashMap<>();
healthMap.put("slug", "health");
healthMap.put("importance", 1);
ArrayList<HashMap> topicList = new ArrayList<>();
topicList.add(healthMap);
...
//Retrofit call
@POST("topics")
Call<String> postBeliefs(@Query("topics") ArrayList<HashMap> topicList);

0 个答案:

没有答案