json - Java - Retrieve values of variable type from JSONObject -
i have json
so:
{"result":[{"job":{"type":"employee","title":"","occupation":"underwater basket weaver"}}]}
i getting occupation value so:
import org.json.jsonarray; import org.json.jsonobject; string occupation = null; jsonarray resultarray = obj.getjsonarray("result"); jsonobject firstresult = resultarray.getjsonobject(0); occupation = firstresult.getjsonobject("job").getstring("occupation");
however, reason, occupation value not string
. guess is int
or null
. end exception this:
org.json.jsonexception: jsonobject["occupation"] not string. @ org.json.jsonobject.getstring(jsonobject.java:658)
what should when dealing jsonobjects take on variable data types?
apply receive data types in string format
occupation = firstresult.getjsonobject("job").get("occupation").tostring();
Comments
Post a Comment