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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -