if (resEntity != null) {
res=EntityUtils.toString(resEntity);
Log.i("RESPONSE",res);
}
xc=res.equals("true");
Log.i("xc",String.valueOf(xc));
if(xc) {
Log.i("Yes","1");
}
else {
Log.i("no","0");
}
上面是我的代码,我在其中向我们公司的服务器发送一个 post 请求以检查文件,如果文件存在则返回 true。我正在提供我的 logcat。
09-24 11:20:19.570: I/url for checking update(3050): http://www.digitalmarketingbox.com/webtool/playerupdate.php
09-24 11:20:33.789: I/RESPONSE(3050): true
09-24 11:20:33.789: I/xc(3050): false
如您所见,从服务器返回的响应是真实的,我也在将其与真实进行比较,那么为什么 equals() 函数返回错误,请帮助我,还是我在这里做错了什么?
最佳答案
我认为最有可能的问题是 res
中的空格。试试这个:
res=EntityUtils.toString(resEntity).trim();
关于java - string.equals() 返回错误值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18973918/