android - java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT (Retrofit 2) -
i such error: java.lang.illegalstateexception: expected begin_array begin_object
, when receive data server. can cause such error? , how fix it?
json receive server:
{ "group": [ { "name": "group1", "description": "test group 1" }, { "name": "group2", "description": "group name updated" } ] }
here api interface:
@get("groups") observable <list<group>> getallgroups(@header("authorization") string auth, @header("content-type") string contenttype, @header("accept") string accept );
method receive data:
private void getallgroups() { string credentials = "admin" + ":" + "admin"; final string basic = "basic " + base64.encodetostring(credentials.getbytes(), base64.no_wrap); string contenttype = "application/json"; string accept = "application/json"; subscription subscription = app.service.getallgroups(basic, contenttype, accept) .subscribeon(schedulers.io()) .observeon(androidschedulers.mainthread()) .subscribe(groups -> { grouplist.addall(groups); }, throwable -> { log.e("all group error", string.valueof(throwable)); }); addsubscription(subscription); }
class group:
public class group { private string name; private string description; public group(string name, string description) { this.name = name; this.description = description; } }
i added class groups:
public class groups { @serializedname("group") list<group> group; }
and changed code in api interface to:
@get("groups") observable <groups> getallgroups(@header("authorization") string auth, @header("content-type") string contenttype, @header("accept") string accept );
and after app starts work without errors.
Comments
Post a Comment