java - JSON No Value For Exception Also how to retrieve values if column names are entered by user -
i have started develop @ android platform , working on prototype.
what doing m retrieving data online database through json column names provided user i.e. information of column should data retrieved provided user eg in database 3 columns - optiona,optionb,optionc present , name of column data retreived provided user .
this json code sending url-
public jsonarray retreivedata(string option,string vendorname,string company,string style,string chimcompany,string shape,string size,string type,string category) { // url getting customers try { url = "http://piyushsharma.byethost16.com/retreivedata.php?option="+option+"&vendorname="+vendorname+"&company="+urlencoder.encode(company,"utf-8")+"&style="+style+"&chimcompany="+chimcompany+"&shape="+shape+"&size="+size+"&type="+type+"&category="+urlencoder.encode(category,"utf-8"); log.e("url",url); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } // httpresponse object url. // httpentity http response object httpentity httpentity = null; try { defaulthttpclient httpclient = new defaulthttpclient(); // default httpclient httpget httpget = new httpget(url); httpresponse httpresponse = httpclient.execute(httpget); httpentity = httpresponse.getentity(); } catch (clientprotocolexception e) { // signals error in http protocol e.printstacktrace(); //log errors here } catch (ioexception e) { e.printstacktrace(); } // convert httpentity json array jsonarray jsonarray = null; if (httpentity != null) { try { string entityresponse = entityutils.tostring(httpentity); log.e("entity response : ", entityresponse); jsonarray = new jsonarray(entityresponse); } catch (jsonexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } return jsonarray; }
this json code retreiving data -
public void savedata(jsonarray jsonarray) { jsonobject json = null; sizeofarray=jsonarray.length(); for(int i=0; i<=sizeofarray;i++){ try { json = jsonarray.getjsonobject(i); parea=json.getstring("area"); pbaskets=json.getstring(company); prizechim=json.getstring("prize"); psnf=json.getstring(type); ptile=json.getstring(size); } catch (jsonexception e) { e.printstacktrace(); } } }
where variables company,type , size passed users. please tell me possible passing variables instead of string. , storing these values displaying them in textview.
this json response -
[{"area":"29"},{"maggpie":"7890"},{"prize":"10000"},{"vintage":"6890"},{"15x10":"375"}]
this exception shown -
03-16 18:28:07.638: w/system.err(3344): org.json.jsonexception:
no value maggpie
03-16 18:28:07.648: w/system.err(3344): @ org.json.jsonobject.get(jsonobject.java:355) 03-16 18:28:07.688: w/system.err(3344): @ org.json.jsonobject.getstring(jsonobject.java:515) 03-16 18:28:07.688: w/system.err(3344): @ com.example.projectkitchennbathroom.estimate.savedata(estimate.java:107) 03-16 18:28:07.688: w/system.err(3344): @ com.example.projectkitchennbathroom.estimate$retreivedata.onpostexecute(estimate.java:140) 03-16 18:28:07.708: w/system.err(3344): @ com.example.projectkitchennbathroom.estimate$retreivedata.onpostexecute(estimate.java:1) 03-16 18:28:07.708: w/system.err(3344): @ android.os.asynctask.finish(asynctask.java:632) 03-16 18:28:07.708: w/system.err(3344): @ android.os.asynctask.access$600(asynctask.java:177) 03-16 18:28:07.708: w/system.err(3344): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645) 03-16 18:28:07.708: w/system.err(3344): @ android.os.handler.dispatchmessage(handler.java:102) 03-16 18:28:07.708: w/system.err(3344): @ android.os.looper.loop(looper.java:136) 03-16 18:28:07.708: w/system.err(3344): @ android.app.activitythread.main(activitythread.java:5017) 03-16 18:28:07.718: w/system.err(3344): @ java.lang.reflect.method.invokenative(native method) 03-16 18:28:07.718: w/system.err(3344): @ java.lang.reflect.method.invoke(method.java:515) 03-16 18:28:07.718: w/system.err(3344): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 03-16 18:28:07.718: w/system.err(3344): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 03-16 18:28:07.718: w/system.err(3344): @ dalvik.system.nativestart.main(native method) 03-16 18:28:07.718: w/system.err(3344): org.json.jsonexception: no value area
i dont know why showing null although value present?
the user input not match stored in json array. due how user input read. should confirm there no hidden characters coming in user input.
system.out.println("company.length() = " + company.length()); system.out.println("company = :" + company + ":");
i can see nothing wrong code provided.
Comments
Post a Comment