Please try this one
Object value = json.get("next");
if(value instanceof Boolean){
boolean booValue = json.getBoolean("next");
}else {
String str = json.getString("next");
}
1
solved How to know whether my json value is boolean or String value contain