java - Getting JSON.typeMismatch trying to convert string coming from an HTTP Get to JSON object -
i have looked @ multiple other answers here still have not been able resolve issue.
i call php restful server json string database. here log output of string comes back:
"{\"pat_list\":[{\"id\":\"1\",\"name\":\"john deere\",\"gender\":\"m\",\"child\":\"n\",\"email\":\"mail@site.com\",\"patientid\":\"12657\",\"pridiag\":\"sick\"}]}"
this looks valid json (it validates) , looks escaped me (it created using json_encode in php on server)
however, when try execute code:
if (json_pat_list != null) { log.d("json_string",json_pat_list); try { jsonobject jsonobj = new jsonobject(json_pat_list);
i get:
w/system.err﹕ org.json.jsonexception: value {"pat_list":[{"id":"1","name":"john deere","gender":"m","child":"n","email":"mail@site.com","patientid":"12657","pridiag":"sick"}]} of type java.lang.string cannot converted jsonobject ... w/system.err﹕ @ org.json.json.typemismatch(json.java:111)
can see missing here?
your code seems legit. far can see. can suggest because generated on php server, might putting in characters malformat string completely.
there 2 things can suggest:
if (json_pat_list != null) { log.d("json_string",json_pat_list); //either string formattedstring = json_pat_list.replaceall("\n", "\\n"); //or can string formattedstring = json_pat_list.substring(s.indexof("{")); try { jsonobject jsonobj = new jsonobject(json_pat_list);
Comments
Post a Comment