改造@FieldMap参数类型必须是Map

时间:2016-01-23 22:05:42

标签: android retrofit

我正在尝试实现一个请求,我可以使用Retrofit同时发送多个请求,因此,我创建了一个这样的接口:

@FormUrlEncoded
@POST("/locations/add.json")
void sendMultipleLocations(@Query("token")String token, @FieldMap List<Map<String, String>> multipleLocations, Callback<String> callback);

然后,我在List中构建地图数据,然后推送。

private void sendLocations(List<Map<String, String>> multipleLocations) {
    RestClient.get(this).sendMultipleLocations("token", multipleLocations, new Callback<String>() {
        @Override
        public void success(String s, Response response) {
            Log.e("MultipleLocationResp", s);
        }

        @Override
        public void failure(RetrofitError error) {
            error.printStackTrace();
        }
    });
}

我一直收到这个错误:

 java.lang.IllegalArgumentException: PodApi.sendMultipleLocations: @FieldMap parameter type must be Map. (parameter #2)
at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
at retrofit.RestMethodInfo.parameterError(RestMethodInfo.java:111)
at retrofit.RestMethodInfo.parseParameters(RestMethodInfo.java:365)
at retrofit.RestMethodInfo.init(RestMethodInfo.java:118)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:0)

您必须使用地图,而不是地图列表。 @FieldMap Map<String, String> multipleLocations