首页 > 解决方案 > 发送键值列表对象进行改造

问题描述

我想发送这个

"question_id": 1,
"answer_id": { 
    "answerId1": "value1",
    "answerId2": "value2"
}

通过在 android 中进行改造

我发了这个

"question_id": 1,
"answer_id": [ 
    1,
    2
    ] 
    

像那样

@FormUrlEncoded
@POST(".....")
@Field("question_id") String questionId, @Field("answer_id[]") ArrayList<String> answerId)

如何对第一个请求做同样的事情?顺便说一句 HashMap<String,String> 不工作

标签: androidhashmapretrofit

解决方案


尝试这个

public interface myService {    

    @POST("/api/mypath/test")
    @FormUrlEncoded
    void getPositionByZip(@Query("question_id") String question_id, @FieldMap Map<String, String> answer_id);
}

// Map params need set key and value pair  like      
// answer_id.put("answerId1","value1");
// answer_id.put("answerId2","value2");

推荐阅读