在我的json中我得到一个键,其中有时它可能带有字符串值,或者可能是布尔值如何确定它来的值。
带字符串的JSON
{
"status" : "success",
"next" : "0.1"
}
与布尔
相同的JSON{
"status" : "success",
"next" : false
}
我如何才能了解" next" key包含String或Boolean值?
答案 0 :(得分:1)
请尝试这个
Object value = json.get("next");
if(value instanceof Boolean){
boolean booValue = json.getBoolean("next");
}else {
String str = json.getString("next");
}