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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -