android - JSON Conversion Exception to java object -
i facing json conversion exception. while converting json java object.
here json
[ { "prefrenceid":"228f176d-d224-32d7-9bb5-6287a06a68e8", "userid":"327e6c64-bc90-3ae8-8f7d-72837581ca13", "questionnaireid":"41f31b11-47f5-3e29-8c88-1a3615c978a7", "suggestions":"", "explanation":"", "isactive":true, "isdelete":false, "datecreated":"2016-11-01 09:53:00.000", "dateupdated":"2016-11-01 09:53:17.000" }, { "prefrenceid":"52a74739-bdd3-33ac-a83f-72f60b1992b5", "userid":"327e6c64-bc90-3ae8-8f7d-72837581ca13", "questionnaireid":"8cd5ac8e-89db-3d7b-bb2d-4e6735b245de", "suggestions":"", "explanation":"", "isactive":true, "isdelete":false, "datecreated":"2016-11-01 09:48:53.000", "dateupdated":"2016-11-01 09:53:15.000" }, { "prefrenceid":"ae7fc877-b26a-34d3-a5f3-244c7e777e08", "userid":"327e6c64-bc90-3ae8-8f7d-72837581ca13", "questionnaireid":"d3b98cde-111c-30d5-a4c9-412a76b656eb", "suggestions":"camping", "explanation":"", "isactive":true, "isdelete":false, "datecreated":"2016-11-01 09:53:02.000", "dateupdated":"2016-11-01 09:53:19.000" }, { "prefrenceid":"bcac0da7-31a6-345f-be82-ddff17c29b35", "userid":"327e6c64-bc90-3ae8-8f7d-72837581ca13", "questionnaireid":"8fb1bda7-7ec8-3538-8aa8-ff84637764a4", "suggestions":"", "explanation":"", "isactive":true, "isdelete":false, "datecreated":"2016-11-01 09:53:07.000", "dateupdated":"2016-11-01 09:53:22.000" }, { "prefrenceid":"ff46ce3c-70cb-3d25-8dbb-10e9c46d4c2d", "userid":"327e6c64-bc90-3ae8-8f7d-72837581ca13", "questionnaireid":"3afffc17-30e4-311f-a0fc-8daa3bda6c98", "suggestions":"", "explanation":"", "isactive":true, "isdelete":false, "datecreated":"2016-11-01 09:53:05.000", "dateupdated":"2016-11-01 09:53:20.000" } ]
my pojo classes :-
public class survivorzamquestionlist implements serializable { public list<survivorzamquestionnaire> survivorzamquestionnaires; } public class survivorzamquestionnaire implements serializable { public string suggestions; public string prefrenceid; public string isactive; public string isdelete; public string datecreated; public string dateupdated; public string userid; public string questionnaireid; public string explanation; }
but when converting json response json showing following error:- com.google.gson.jsonsyntaxexception: java.lang.illegalstateexception: expected begin_object begin_array @ line 1 column 2
can tell me missing in pojo class. kind of held should appreciated.
your response proper parsing not proper. first of add gson in gradle file.
compile 'com.google.code.gson:gson:2.4'
now use below code parsing response
try { jsonarray array = new jsonarray("put response here"); gson gson = new gson(); (int = 0 ; <array.length();i++) { survivorzamquestionnaire obj = new survivorzamquestionnaire(); obj.add(gson.fromjson(array.getjsonobject(i).tostring(),survivorzamquestionnaire.class)); } } catch (jsonexception e) { e.printstacktrace(); }
add obj in list , show :)
Comments
Post a Comment