android - Retrofit - java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT -
i trying parse own json, getting jsonsyntaxexception
, here how json looks:
{ "type":"success", "value":[ { "id":1, "title":"title - 1", "name":{ "first":"first - 1", "last":"last - 1" }, "hobbies":[ "writing code - 1", "listening music - 1" ] }, ..... ] }
log says:
e/app.retrofit_chucknorries.mainactivity$2: error: com.google.gson.jsonsyntaxexception: java.lang.illegalstateexception: expected begin_array begin_object @ line 7 column 12 path $.value[0].name 01-21 12:41:52.156 28936-28936/app.retrofit_chucknorries w/system.err: retrofit.retrofiterror: com.google.gson.jsonsyntaxexception: java.lang.illegalstateexception: expected begin_array begin_object @ line 7 column 12 path $.value[0].name
where doing mistake ?
made few small modifications per requirement , classes
else same in original code value.java:
import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname; import java.util.arraylist; import java.util.list; public class value { @serializedname("id") @expose private integer id; @serializedname("title") @expose private string title; @serializedname("hobbies") @expose private list<string> hobbies = new arraylist<string>(); @serializedname("name") @expose private list<name> name = new arraylist<name>(); public integer getid() { return id; } public void setid(integer id) { this.id = id; } public list<name> getname() { return name; } public void setname(list<name> name) { this.name = name; } public list<string> gethobbies() { return hobbies; } public void sethobbies(list<string> hobbies) { this.hobbies = hobbies; } public string gettitle() { return title; } public void settitle(string title) { this.title = title; } }
in master.java class, name not array!
private list<name> name = new arraylist<name>();
change instead , try:
private name name;
actually seeing logs of exception can tell this.
Comments
Post a Comment