在Android

时间:2015-10-10 23:19:48

标签: android server retrofit

我正在使用Retrofit进行服务器调用。我需要将JSONArray发送到服务器。我的JSONArray看起来像 -

[{"callName”:”xxx”},{“inputData":{"deviceImei”:”xxxx”,”appVersionUser”:”x”,”osVersion”:”x”,”osType”:”x”,”deviceToken”:”xxxx”}}]

我正在使用RetroFit版本1.9.0。我尝试使用@BODY。但是我收到了这个错误 -

retrofit.RetrofitError: APIClass.GetClientAuthentication: @Body parameters cannot be used with form or multi-part encoding"

我的Api功能声明是,

@FormUrlEncoded
@POST("/XYZ")
void GetClientAuthentication(@Body JSONArray jArray,
                             Callback<AuthenticationCallBack> aPOJOCallback);

有人可以帮忙吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

嘿,我终于解决了它

在接收部分,我在JSONElement中接受了响应并将其转换为POJO类,如下所示。 AuthenticationErrorJsonResponse.java是我的POJO类。

ArrayList<AuthenticationErrorJsonResponse> yourArray = new Gson().fromJson(authenticationJsonResponse.toString(),
                                new TypeToken<List<AuthenticationErrorJsonResponse>>(){}.getType());