android - org.json.JSONException: Value of Feedback type java.lang.String cannot be converted to JSONArray while converting jsonstring to object -
i new in android development..i want remove object jsonstring. have jsonstring , converting string json object , array..remove object jsonobject , again convert jsonstring ,save string db..
but got error org.json.jsonexception: value feedback of type java.lang.string cannot converted jsonarray
here code:
public jsonarray convertjsonstringtoarray() { jsonarray jsonarray=new jsonarray(); string select_json= customizeadapter.selectcustomizeentry_jsonmodified(); log.e("json string select",select_json); try { jsonobject jsnobject = new jsonobject(select_json); jsonarray = new jsonarray("feedback"); jsonarray = jsnobject.getjsonarray("feedback"); (int = 0; < jsonarray.length(); i++) { jsonobject explrobject = jsonarray.getjsonobject(i); } }catch (exception j){ log.e("exception json", j.tostring()); } removejsonarray(jsonarray); log.e("json array",jsonarray.tostring()); return jsonarray; } public static jsonarray removejsonarray( jsonarray jarray) { jsonarray njarray=new jsonarray(); try{ for(int i=0;i<jarray.length();i++){ if(i!=1) njarray.put(jarray.get(i)); } }catch (exception e){e.printstacktrace();} return njarray; } here select_json :
{"id":0,"name":null,"email":null,"fields":{"feedback":[{"min":"1","max":"1000","visible":"1","params":"","access":"","registration":"1","type":"text","option1":"","id":1,"option2":"","option3":"","option4":"","fieldcode":"fieldght66yh","name":"ght66yh","value":"","ordering":1,"tips":"ght66yh","required":"0","published":"1","searchable":"1","options":""},{"min":"1","max":"1000","visible":"1","params":"","access":"","registration":"1","type":"text","option1":"","id":2,"option2":"","option3":"","option4":"","fieldcode":"fieldbgfhtuu","name":"bgfhtuu","value":"","ordering":2,"tips":"bgfhtuu","required":"0","published":"1","searchable":"1","options":""}]}}
try below code parse json response .
try { jsonobject jsonobject = new jsonobject(response);// here response json string string id = jsonobject.getstring("id"); /** * same way can other string value */ jsonobject obj = jsonobject.getjsonobject("fields"); jsonarray array2 = obj.getjsonarray("feedback"); (int = 0; < array2.length(); i++) { jsonobject jsonobject2 = array2.getjsonobject(i); ///do here } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); }
Comments
Post a Comment