Wednesday, 15 September 2010

android - JSONException: End of input at character 0 -



android - JSONException: End of input at character 0 -

i trying json values server. don't know wrong code. using asynctask , here code in doinbackground

code:

@override protected void doinbackground(list<string>... articlesrec) { (list<string> articlespostvalue : articlesrec) { event = articlespostvalue.get(0); category = articlespostvalue.get(1); paged = articlespostvalue.get(2); deviceid = articlespostvalue.get(3); } list<namevaluepair> articlespostvalues = new arraylist<namevaluepair>(); articlespostvalues.add(new basicnamevaluepair("_event", event)); articlespostvalues.add(new basicnamevaluepair("cat", category)); articlespostvalues.add(new basicnamevaluepair("paged", paged)); articlespostvalues.add(new basicnamevaluepair("_deviceid", deviceid)); httpclient hc = new defaulthttpclient(); httppost hp = new httppost(autolifeconstants.base_url); seek { hp.setentity(new urlencodedformentity(articlespostvalues)); // execute http post request httpresponse response = hc.execute(hp); string result = entityutils.tostring(response.getentity()); string jsontext = new string(result); jsonobject entries = new jsonobject(jsontext); this.response = entries.getstring("response_code"); seek { string totalpagestr = entries.getstring("total_pages"); totalpage = integer.valueof(totalpagestr); } grab (exception e) { } jsonarray postlistarray = entries.getjsonarray("posts_list"); (int = 0; < postlistarray.length(); i++) { jsonobject postlistobj = postlistarray.getjsonobject(i); string articlestitle = postlistobj.getstring("title"); string datetime = postlistobj.getstring("date"); string articlesimage = postlistobj.getstring("feature_image"); string descrition = postlistobj.getstring("content"); string fulldescription = postlistobj.getstring("full_content"); articlesnewesttitle.add(articlestitle); articlesnewestposttime.add(datetime); articlesnewestpostimage.add(articlesimage); articlesnewestpostdescription.add(descrition); postfulldescription.add(fulldescription); log.d("title",articlestitle); } } grab (exception e) { log.e("catched error","exceptin occured"); e.printstacktrace(); } homecoming null; }

and here catch(exception e) on logcat

06-19 13:22:32.229: w/system.err(19647): org.json.jsonexception: end of input @ character 0 of 06-19 13:22:32.264: w/system.err(19647): @ org.json.jsontokener.syntaxerror(jsontokener.java:450) 06-19 13:22:32.265: w/system.err(19647): @ org.json.jsontokener.nextvalue(jsontokener.java:97) 06-19 13:22:32.268: w/system.err(19647): @ org.json.jsonobject.<init>(jsonobject.java:154) 06-19 13:22:32.269: w/system.err(19647): @ org.json.jsonobject.<init>(jsonobject.java:171) 06-19 13:22:32.270: w/system.err(19647): @ np.com.autolife.adapters.newsactivity$get_postlist.doinbackground(newsactivity.java:169) 06-19 13:22:32.272: w/system.err(19647): @ np.com.autolife.adapters.newsactivity$get_postlist.doinbackground(newsactivity.java:1) 06-19 13:22:32.272: w/system.err(19647): @ android.os.asynctask$2.call(asynctask.java:287) 06-19 13:22:32.273: w/system.err(19647): @ java.util.concurrent.futuretask.run(futuretask.java:234) 06-19 13:22:32.273: w/system.err(19647): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 06-19 13:22:32.274: w/system.err(19647): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 06-19 13:22:32.274: w/system.err(19647): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 06-19 13:22:32.281: w/system.err(19647): @ java.lang.thread.run(thread.java:838)

here json format

{ "get": [], "post": { "_event": "get_posts", "_deviceid": "490154203237518", "cat": "2", "paged": "1" }, "response_code": "success", "posts_total": 8, "total_pages": 2, "paged": 1, "posts_list": [ { "id": 9168, "title": "maxxis introduce trepador tires", "content": "", "full_content": "http:xxxxxx", "date": "june 13, 2014", "category": "all news & events, local news", "feature_image": "http:xxxxx.jpg", "feature_image_thumb": "http:xxxx.jpg", "author": "autolife team" }, { "id": 9162, "title": "5 year warranty on hero motorcycles", "content": "", "full_content": "http://xxxxx", "date": "june 13, 2014", "category": "all news & events, local news", "feature_image": "http://xxxxxx.jpg", "feature_image_thumb": "http://xxxx.jpg", "author": "autolife team" }, { "id": 8130, "title": "all new 11th generation toyota corolla launched", "content": "", "full_content": "http://xxxxxx", "date": "may 1, 2014", "category": "events & schemes", "feature_image": "http://xxxxxx.png", "feature_image_thumb": "http://xxxxxx.png", "author": "supervisor" }, { "id": 9178, "title": "new launches tata motors : tata nano twist", "content": "", "full_content": "http://xxxxxx", "date": "february 15, 2014", "category": "all news & events, international news", "feature_image": "http://xxxxx.jpg", "feature_image_thumb": "xxxxxxx.jpg", "author": "autolife team" }, { "id": 9175, "title": "new launches tata motors : revotron engine", "content": "", "full_content": "xxxxxxx", "date": "february 15, 2014", "category": "all news & events, international news", "feature_image": "http://xxxxx.jpg", "feature_image_thumb": "http://xxxxx.jpg", "author": "autolife team" } ] }

you getting blank response. not null jsontext empty. getting error , not nullpointer exception

are sending right parameters server.also check url respond post requests or not.

android json android-asynctask

No comments:

Post a Comment