将body写到文本或输出就会自动将转义去掉,所以发出来的文本是不能解析的,
双引号在没有转成文本前前面是有转义符的,输出成文本就会去掉转义符,
所以需要:将响应body进行json反序列化
public static String doGet(String url, int connTimeout, int readTimeout, String charset, Map<String, String> headerMap) {
......
GetMethod method = new GetMethod(url);
if (statusCode == HttpStatus.SC_OK) {
//将响应body进行json反序列化
String res = getRequestBodyJson(method.getResponseBodyAsStream());
}
......
}
private static String getRequestBodyJson(InputStream inputStream) throws IOException {
Reader input = new InputStreamReader(inputStream);
Writer output = new StringWriter();
char[] buffer = new char[1024 * 4];
int n;
while(-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toString();
}