我正在为安卓开发一个客户端应用程序,我的应用程序接口要求我用ArrayList<String>发送图片名称,如下所示:
collection[0] = 15a877ce9f22bc8349cac80565c4bff6.jpg
collection[1] = 25a877ce9f22bc8349cac80565c4bff6.jpg但当我发送它时,它的格式如下:
collection[] = 15a877ce9f22bc8349cac80565c4bff6.jpg
collection[] = 25a877ce9f22bc8349cac80565c4bff6.jpg我的翻新界面:
@Field("collection[]") ArrayList<String> collection);如何才能达到想要的效果?
任何帮助都将不胜感激!谢谢!
发布于 2016-12-09 03:14:32
不要将[]放在@Field名称中,我不知道你为什么要这样做,但这可能会让人感到困惑,因为这些都是保留字符……
您可以使用类似以下内容:
// ApiService.java
@FormUrlEncoded
@POST("/api/projectLost")
public void projectMarkLost(
@Field("apiKey") String apiKey,
@Field("project_id") int projectId,
@Field("lost_project_remark") String lostProjectRemark,
@Field("lost_project_reasons") ArrayList<Integer> lostProjectReasons,
Callback<JsonObject> cb
);
// Content wish to post
POST content:
apiKey = EzAvFvScs45a2DRI0MktdIDeVRbP59
project_id = 986
remark = testing
details = [detail_1,detail_2]发布于 2016-12-10 21:06:11
我找到了一个使用Map来实现理想结果的解决方案
@FormUrlEncoded
@POST("user/news")
Call<CreateNews> createNews(
@Field("text") String text,
@FieldMap Map<String, String> collection);在方法上:
public void createNews(String text, ArrayList<String> collection, final Callback<CreateNews> callback){
News createNews = ServiceGenerator.createService(News.class);
SortedMap fields = new TreeMap<String, String>();
for (int i = collection.size()-1 ; i >= 0 ; i--) {
fields.put("collection["+i+"]", collection.get(i));
}
Call<CreateNews> call = createNews.createNews(text, fields);
call.enqueue(callback);https://stackoverflow.com/questions/41046354
复制相似问题