In Java, I know you can check if a key is present with the isNull() method. Is there a way to check what kind of data the key holds?
Consider the following examples.
I would want a function like JSONBody.getDataType("key") and it would return String
{
"key" : "value"
}
I would want a function like JSONBody.getDataType("key") and it would return JSONObject
{
"key" : {
"parm1" : "value1",
"parm2" : "value2"
}
}
I would want a function like JSONBody.getDataType("key") and it would return JSONArray
{
"key" : [
"value1",
"value2",
"value3"
]
}
I would want a function like JSONBody.getDataType("key") and it would return Boolean
{
"key" : true
}
Does something like this exist?
JSONObject stuff = new JSONObject(whatever);
Object thing = stuff.get("key");
String classNameOfThing = thing.getClass().getName();
Systen.out.println("thing is a " + classNameOfThing);
if (thing instanceof Integer) {
System.out.println("thing is an Integer");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With