嗨,我正在尝试用Java修补JSONObject(或Json字符串),但我遇到了错误的请求。而且我不明白问题是出在Path-Methode还是JSONObject
PS:这是我第一次使用Server和Patch。我试图在网上查找,但没有任何帮助
感谢答案
这里是我的路径方法
public static void pathMethod() throws IOException {
HttpClient httpclient = HttpClientBuilder.create().build();
JSONObject jsonData = getJsondata();
HttpPatch req = new HttpPatch("http:URL");
req.setHeader("Content-type", "application/json");
if (jsonData != null) {
final StringEntity stringData = new StringEntity(jsonData.toString());
req.setEntity(stringData);
}
HttpResponse httpResponse = httpclient.execute(req);
System.out.println(httpResponse);
}
此处为JSONObject
public static JSONObject getJsondata (){
JSONObject j = new JSONObject(
"{" +
"\"op\": \"replace\"," +
"\"path\": \"/name/family\"," +
" \"value\": \"Paul\"" +
" }"
);
return j;
}
谢谢