我有了这个代码,目前通过新泽西州的客户端发送的JSON对象在Java/Groovy:在如何发送groovy map作为泽西休息客户端中的参数发送请求?
webResource = client
.resource(endPointUrl)
.header("Content-Type", "application/json");
def details = [
name : nameVar,
start : startDate,
end : endDate,
status: 1
]
JSONObject jsonString = new JSONObject(details);
ClientResponse response = webResource
.header("Content-Type", "application/json")
.header('Cookie', userCookie)
.post(ClientResponse.class, jsonString);
我想要做的就是发送details
地图,而将其转换为JSONObject的,因为我想从我的项目中删除该依赖项。有可能吗?如果我尝试.post(ClientResponse.class, details);
它不起作用,因为地图的格式与JSON格式不同。任何帮助将不胜感激
你看过'groovy.json.JsonBuilder()'吗? – Armaiti