java - How can the datatype of a JSON property be determined? -
in java, know can check if key present isnull() method. there way check kind of data key holds?
consider following examples.
i want function jsonbody.getdatatype("key") , return string
{ "key" : "value" }
i want function jsonbody.getdatatype("key") , return jsonobject
{ "key" : { "parm1" : "value1", "parm2" : "value2" } }
i want function jsonbody.getdatatype("key") , return jsonarray
{ "key" : [ "value1", "value2", "value3" ] }
i want function jsonbody.getdatatype("key") , return boolean
{ "key" : true }
does exist?
jsonobject stuff = new jsonobject(whatever); object thing = stuff.get("key"); string classnameofthing = thing.getclass().getname(); systen.out.println("thing " + classnameofthing); if (thing instanceof integer) { system.out.println("thing integer"); }
Comments
Post a Comment