Error parsing JSON data in android -
this question has answer here:
- how parse json in android 4 answers
facing jsonexception
while parsing json string
exception :
org.json.jsonexception: value anytype of type java.lang.string cannot converted jsonarray
code snippet.
try { androidhttptransport.call(soap_action1, envelope); soapobject response = (soapobject) envelope.getresponse(); string resp=response.tostring(); log.d("resp",response.tostring()); // newwwwww try { jsonarray jsonarray = new jsonarray(resp); (int = 0; < jsonarray.length(); i++) { jsonobject c = jsonarray.getjsonobject(i); system.out.println(c.getint("mst_bloodgroupid")); system.out.println(c.getstring("bloodgroup_name")); } } catch (jsonexception e) { e.printstacktrace(); } }
response.tostring() below:
anytype{schema=anytype{element=anytype{complextype=anytype{choice=anytype{element=anytype{complextype=anytype{sequence=anytype{element=anytype{}; element=anytype{}; }; }; }; }; }; }; }; diffgram=anytype{documentelement=anytype{table=anytype{mst_bloodgroupid=1; bloodgroup_name=a+; }; table=anytype{mst_bloodgroupid=2; bloodgroup_name=a-; }; table=anytype{mst_bloodgroupid=3; bloodgroup_name=b+; }; table=anytype{mst_bloodgroupid=4; bloodgroup_name=b-; }; table=anytype{mst_bloodgroupid=5; bloodgroup_name=ab+; }; table=anytype{mst_bloodgroupid=6; bloodgroup_name=ab-; }; table=anytype{mst_bloodgroupid=7; bloodgroup_name=o+; }; table=anytype{mst_bloodgroupid=8; bloodgroup_name=o-; }; }; }; }
private class getcategories extends asynctask {
@override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("fetching.."); pdialog.setcancelable(false); pdialog.show(); } @override protected void doinbackground(void... arg0) { servicehandler jsonparser = new servicehandler(); string json = jsonparser.makeservicecall(url_categories, servicehandler.get); log.e("response: ", "> " + json); if (json != null) { try { jsonobject jsonobj = new jsonobject(json); if (jsonobj != null) { jsonarray categories = jsonobj .getjsonarray("categories"); (int = 0; < categories.length(); i++) { jsonobject catobj = (jsonobject) categories.get(i); system.out.println(catobj.getint("id")); system.out.println(catobj.getstring("name")); } } } catch (jsonexception e) { e.printstacktrace(); } } else { log.e("json data", "didn't receive data server!"); } return null; }
Comments
Post a Comment