【发布时间】:2018-03-08 15:02:32
【问题描述】:
Retrofit2 我将如何使用具有内部 json 的地图 json 主体发布。让我给你举个例子:
{
"id_invoice": 1234,
"action": "viewed",
"data": {
"id_object": 88,
"id_store": 43,
"type": "payment"
}
}
注意“数据”JSON 对象如何具有内部 JSON。如何将所有这些放入地图中,以便使用以下服务端点将其发送到改造:
public interface Api {
@NonNull
@POST("cart/payment")
@Headers({"Content-Type:application/json"})
Observable<ResponseBody> postPaymentEvent(@Body Map<String, Object> body);
}
我尝试了以下方法:
Map<String, Object> map = new HashMap<>();
JSONObject json = new JSONObject();
json.put("id_object", 88);
json.put("id_store", 43);
json.put("type", "payment");
map.put("action", "view");
map.put("id_invoice", 1234);
map.put("data", json); //this is wrong. it creates the following response with a nameValuePairs field, which is not what i want:
正文:
{
"action": "page_view",
"id_invoice": "1234",
"data": {
"nameValuePairs": {
"id_object": 88,
"id_store": 43,
"type": "view"
}
}
}
【问题讨论】: