我正在尝试使用以下代码解析下面的json响应,但代码在普通eclipse程序上工作正常但在tomcat (java 1.8)
上失败
2016-12-20 00:18:17,146 DEBUG c.a.f.u.s.UpdateFileUploadData [Thread-35] sTempOutput ::" [{\"状态\":\"成功\" \" MonthlyReportId \":\" R / I - 000913 \"},{\"状态\":\"成功\" \" MonthlyReportId \":\" R / I - 001473 \"},{\"状态\":\"成功\" \" MonthlyReportId \":\" R / I - 001474 \"}]" 2016-12-20 00:18:17,146 DEBUG c.a.f.u.s.UpdateFileUploadData [Thread-35] 转化:[{\" Status \":\" Success \",\" MonthlyReportId \":\" R / I - 000913 \"},{\"状态\":\"成功\" \" MonthlyReportId \":\" R / I - 001473 \"},{\"状态\":\"成功\" \" MonthlyReportId \":\" R / I - 001474 \"}]
jsonObject = jsonObject.replaceAll("\\\"", "\"");
if(jsonObject.startsWith("\"")){
jsonObject = jsonObject.substring(1, jsonObject.length()-1);
} // replacing the " from start and end.
if (logger.isDebugEnabled()) {
logger.debug("transformed:{}", jsonObject);
}
org.json.JSONArray array = new org.json.JSONArray(jsonObject);
if (logger.isDebugEnabled()) {
logger.debug("array:::{}", array);
}
DBAdapter dbAdapter = new DBAdapter();
for (int start = 0 ;start<array.length(); start++){
JSONObject object = array.getJSONObject(start);
String status = (String)object.get("Status");
String monthlyReportId = (String)object.get("MonthlyReportId");
if (logger.isDebugEnabled()) {
logger.debug("status:::{}", status);
logger.debug("monthlyReportId:::{}", monthlyReportId);
}
}
这是在扼杀我。我也试过了 -
jsonObject = jsonObject.replaceAll("(\\r|\\n|\\r\\n)+", "");
jsonObject = jsonObject.replaceAll("\\\"", "\"");
休息时间保持不变。