Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

JSONException in BlogReader App

Hi friends,

When I am trying to fetch the detail from following URL http://blog.teamtreehouse.com/api/get_recent_summary/?count=20

I am getting following JSON.

{"status":"ok","count":5,"count_total":1916,"pages":384,"posts":[{"id":24535,"url":"http:\/\/blog.teamtreehouse.com\/new-courses-angularjs-css-basics-ruby-objects-classes","title":"New Courses: AngularJS, CSS Basics & Ruby Objects","date":"2014-12-11 09:00:24","author":"Gill Carson","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/12\/TeacherShoot-Guil-150x150.jpg"},{"id":24521,"url":"http:\/\/blog.teamtreehouse.com\/everything-need-know-watchkit","title":"Everything You Need To Know About Watchkit","date":"2014-12-10 11:53:14","author":"Amit Bijlani","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/12\/iwatch-150x150.png"},{"id":24530,"url":"http:\/\/blog.teamtreehouse.com\/svg-animations","title":"SVG Animations","date":"2014-12-09 20:47:30","author":"Jason Seifer","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/12\/m5dxf-150x150.jpg"},{"id":24524,"url":"http:\/\/blog.teamtreehouse.com\/free-talk-css-accessibility","title":"Free Talk: CSS, Accessibility and You!","date":"2014-12-08 13:29:47","author":"Gill Carson","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/12\/css_conf-150x150.jpg"},{"id":24507,"url":"http:\/\/blog.teamtreehouse.com\/mary-brought-web-based-ambitions-life-working-full-time-raising-kids","title":"Mary Learned to Code While Working Full-time & Raising Kids","date":"2014-12-05 09:01:54","author":"Faye Bridge","thumbnail":"http:\/\/blog.teamtreehouse.com\/wp-content\/uploads\/2014\/12\/Mary-150x15������������������

I don't know why I am getting those special weird characters at the end. Due to those characters I am getting following exception:

org.json.JSONException: Unterminated string at character 1556

What am I doing wrong?

2 Answers

bump

Tarun, I was having the same issue and found this post helpful: https://teamtreehouse.com/forum/exception-caught-2

I used the following code:

String response = "";
int nextCharacter = 0;
do {
  nextCharacter = reader.read();
  response += (char) nextCharacter;
} while (nextCharacter != -1);