java - 从java中的JSONObject中删除特殊字符
问题描述
我正在通过返回 xml 的 java 调用 API。
我的代码是:
JSONObject responses_obj = new JSONObject();
string url = "http://localhost:8080/myAPI";
URL obj = new URL(null, url , new sun.net.www.protocol.http.Handler());
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
String urlParameters = "{\"patient_id\":" +"\"" +document_id_list[2] +"\", \"dob\" : " + "\"" + date_of_birth + "\", \"document_id\" : " + "\""+ document_id + "\"}";
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text");
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer responseJSON = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
responseJSON.append(inputLine);
System.out.println(responseJSON);
responses_obj.put("getDocument",responseJSON);
}
in.close()
当我打印 responseJSON 时,我可以看到它。但是,当我在浏览器中查看response_obj 的内容时,我可以看到如下内容:<ClinicalDocument xmlns=\"urn:hl7-org:v3\" xmlns:epsos=\"....
正确的应该是<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="...
有没有办法删除这些“\”字符?
解决方案
推荐阅读
- vim - 用相同长度的空格替换一个单词(或多个单词)?
- google-apps-script - 如果没有付费帐户,就无法从 Google Apps 脚本访问 Google Drive?
- flutter - 获取列表 JSON 到 DropdownMenuItem?
- .net-core - 如何在 gremlin.net 中更新/添加顶点属性
- python - 使用 PIL 和 BytesIO 通过 python 中的套接字发送图像时,图像似乎被随机截断
- autodesk-forge - Forge Viewer BoxSelection Extension - 如何设置选择的深度
- java - 在独立的本地环境中运行 solr start (SOLR 8) 时出现 javax.naming.NoInitialContextException
- angular - 如何测试订阅的价值变化?
- r - 在 rmarkdown 的 ggplot 中为 pdf ( 乳胶 ) 添加希腊字母
- android-studio - 使用 android FFMPEG 库处理有限的视频帧