我有一个类:
public class PetModel{
Serialized("cat")
String cat;
Serialized("dog")
String dog;
// getters and setters
}
当我像这样使用改造进行 POST 时:
@FormUrlEncoded
@POST("/pet/{id}")
Pets postPets(@Path("id") String id,@Field("pets") ArrayList<PetModel> pets);
在日志中我看到发送 <package_name>.PetModel@cc49e70
的请求而不是发送值本身。我做错了什么?
最佳答案
请尝试以下方法,也许你会得到解决方案
PrintWriter out = response.getWriter();
List<Countries> country = new ArrayList<Countries>();
country = FetchData.getAllCountries();
JSONObject js = new JSONObject();
js.put("countries", country); // make sure the Country class overrides toString()
// set the response content-type
response.setContentType("application/json");
// writing the json-array to the output stream
out.print(js.toJSONString());
out.flush();
关于java - 使用 Retrofit 在 POST 请求中发送数组列表会发送带有内存地址的对象,而不是发送值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45837848/