BufferedReader reader=new BufferedReader(new InputStreamReader(c.getInputStream()));
StringBuilder buf = new StringBuilder();
String line;
while ((line=reader.readLine()) != null) {
buf.append(line);
}
return(buf.toString());
如果我的响应字符串中有换行符,那么 buf.toString()中的换行符是否会返回?或者通过追加声明丢失换行符?
答案 0 :(得分:1)
readLine()仅读取排除所有行结束字符的行内容。
while ((line=reader.readLine()) != null) {
buf.append(line);
buf.append("\n");
}
可能是您可以将代码更改为类似的内容,以便在每行后附加行终止字符。
答案 1 :(得分:1)
您可以使用以下代码段
之类的内容while ((line = reader.readLine()) != null) {
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
// But it does make debugging a *lot* easier if you print out the completed
// buffer for debugging.
buffer.append(line + "\n");
}
希望这有助于你...... 干杯