[英]System.out.println always outputs HASH(0x…)
无论我是否指定要打印为“ line”或“ line.toString()”的变量,下面的System.out.println语句始终将诸如“ HASH(0x ....)”之类的哈希引用输出到logcat。 如何获取它以打印实际的字符串值?
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();
}
您的代码没有错。 您可以将循环上方的所有代码替换为更简单的内容,例如:
FileInputStream fstream = new FileInputStream("somefile");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream,"utf-8"));
String line;
while ((line = br.readLine()) != null) {
System.out.println("Line: " + line);
}
br.close();
您将看到文件的内容。
请注意,我不需要执行.toString()
因为变量已经是字符串。
我在这里怀疑的是服务器正在向您发送一个压缩的主体,并且每一行都作为哈希发送,因为这是压缩的定义,全部以十六进制表示。
内容是json,但已对其进行压缩以提高大小和速度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.