java - Error: expected END_ARRAY but was STRING - only on specific phones when using mobile internet -


i have android application in data web services using json.

i have tested application on multiple mobile phones (samsung galaxy s2/s4, htc one/ 1 s, lg, sony .... ) , problem getting when using mobile internet (on wifi works fine) on devices (htc 1 s, huawei ascend p6) error: expected end_array string , nothing downloads.

i can not wrap mind why happening on devices. did experience similar? please help.

note: using gson same problem happened when used json.

json data:

[{"id":"1","name":"germany"}] 

class:

public class language {     @serializedname("id")     public int id;      @serializedname("name")     public string name; } 

code:

try {     this.httpclient = new defaulthttpclient();     this.httppost = new httppost(webserviceurl);     this.httppost.setentity(new urlencodedformentity(this.namevaluepairs));     this.httpresponse = this.httpclient.execute(this.httppost);     this.httpentity = this.httpresponse.getentity();     this.islanguage = this.httpentity.getcontent();      if (this.httpresponse.getstatusline().getstatuscode() == 200)     {         gson gson = new gson();         reader reader = new inputstreamreader(this.islanguage, "utf-8");         language[] xy = gson.fromjson(reader, language[].class);         (int i=0; i<xy.length; i++)             log.i("language-gson", "id: " + xy[i].id + " - name: " + xy[i].name);      } }catch (exception e) { log.i("language-gson", "exception -> " + e.getmessage()); } { this.islanguage.close(); } 

exception:

java.lang.illegalstateexception: expected end_array string @ line 1 column 1

change to

this.httpclient = new defaulthttpclient(); this.httppost = new httppost(webserviceurl); this.httppost.setentity(new urlencodedformentity(this.namevaluepairs)); this.httpresponse = this.httpclient.execute(this.httppost); httpentity httpentity = httpresponse.getentity(); string response = entityutils.tostring(httpentity); gson gson = new gson(); language[] xy = gson.fromjson(response, language[].class); (int i=0; i<xy.length; i++) {      log.i("language-gson", "id: " + xy[i].id + " - name: " + xy[i].name); } 

i justed testing paring of json gson locally. works. if not working need check response form server. parsing code fine.

also check if networkconnection available before making http request. check if response null or not.

it has nothing specific devices or mobile internet. has response server.

i guessing response not valid json. due check response logging same.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -