java系统。出来println总是输出散列(0x……)
系统。出来下面的println语句总是向logcat输出一个散列引用,比如“hash(0x….)”无论我是否将要打印的变量指定为“line”或“line.toString()”。如何让它打印实际的字符串值
URL object=new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
try {
con.setRequestMethod("POST");
} catch (ProtocolException e) {
e.printStackTrace();
}
OutputStreamWriter wr;
try {
wr = new OutputStreamWriter(con.getOutputStream());
wr.write(json.toString());
wr.flush();
} catch (IOException e) {
e.printStackTrace();
}
int HttpResult = con.getResponseCode();
if (HttpResult == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
String line;
while ((line = br.readLine()) != null) {
System.out.println("Line: " + line.toString());
}
br.close();
}
# 1 楼答案
你的代码没有问题。您可以用更简单的代码替换循环上方的所有代码,例如:
您将看到文件的内容
注意,我不需要执行
.toString()
,因为变量已经是字符串了我在这里怀疑的是,服务器正在向您发送一个压缩的正文,每一行都是一个散列,因为这是压缩的定义,都是十六进制的
内容是json,但经过压缩以提高大小和速度