我想通过POST参数的类型是json在retrofit2中就像下面给出的!如何在retrofit2 android中传递POST参数类型json,?
{"person":{"phone":99999,"first_name":"fl","last_name":"asdad","email":"[email protected]", "home_address":{"country_code":"in","zip":123456}}}
如何我可以通过它?
例如
@Headers({"Accept:application/json", "Content-Type:application/json;"})
@POST(WS.profile_new_user)
Call<ProfilePOJO> peopleRegister(@QueryMap Map<String, String> objectMap);
Call<ProfilePOJO> call = Api_Handler.getApiService().peopleRegister(getJsonString());
call.enqueue(new Callback<ProfilePOJO>() {
@Override
public void onResponse(Call<ProfilePOJO> call, Response<ProfilePOJO> response) {
if (response.isSuccessful()) {
Toast.makeText(context, "done", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(context, "error", Toast.LENGTH_SHORT).show();
Log.e("response", new Gson().toJson(response.body()));
}
@Override
public void onFailure(Call<ProfilePOJO> call, Throwable t) {
}
});
public String getJsonString() {
Map<String, String> map = new HashMap();
map.add("",""); //i stuck @ here.i don't know how to pass json type as a parameter here.
return map;
}
作为参数我的类型是JSON,其值高于JSON字符串。 预先感谢您。
的可能的复制[如何在改造请求的主体立柱鲜全脂JSON?](https://stackoverflow.com/questions/21398598/how-to-post-raw-whole-json-请求) – moritzg