这里是我的代码:字符串解释为布尔
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String temp = reader.readLine();
if(temp!=null)
result = new JSONObject(temp);
} catch (Exception e) {
e.printStackTrace();
}
正如你看到的,我给你串来串类型的对象,但是当代码运行,result="true"
我得到异常:
价值的真实java.lang.Boolean类型不能被转换为JSONObject的
这是令人沮丧的。我应该为一个String对象铸造或使用.toString()
?为什么它会自动转换为布尔值?
更新 我已经想通了,这不是Java问题,但JSONObject构造函数没有收到有效的JSONObject。
嗯,'true'不是一个JSON对象,它是一个JSON布尔... – fge
变量'temp'的值是什么?这可能是“真的”吗? – AlexR
我在帖子中已经提到它:result =“true” –