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

Converting a website into JSON

Hello everyone. I recently completed the Android learning adventure, and made both the Crystal Ball app, and the BlogReader app. I loved the videos, and learned a lot.

My question is regarding the BlogReader app. I was thinking of how to extend this. Is there anyway that I could convert my own website into a JSON feed? The same way Ben converted blog.teamtreehouse.com into a JSON feed using http://blog.teamtreehouse.com/api/get_recent_summary/

6 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

If you are using WordPress, then you can use the JSON API plugin. Amit Bijlani found this for us (see his answer to a similar question which includes a link to a gist you can use as well).

Oh, I scanned the forum before writing but didn't find this. Stupid of me. Anyway, thanks Ben, keep up the great work. Looking forward to the next app!

Sorry for double posting, but I've encountered another problem. After following all the steps, and installing the plugin and implementing the function in the core.php, I was able to convert my website into a similar JSON view, Now it displays correctly when I type : http://codingmash.com/api/get_recent_summary/?count=20

However, my application doesn't work. After debugging, I've found out that in the doInBackground() method, it establishes an ok HTTP connection, and thus goes into the try block. Here, it throws an exception at the line:

char [] chararray = new char [contentLength];

In the debugger, I found out that the contentLength variable was -1 after using the getContentLength(). And this was probably the reason the exception occurs. But I have no idea why it returns -1. Ive tried changing it from int to long, just to see if there were simply too many characters, but it still returns -1.

Can anyone help? :(

I get this same -1 error when I try http://strong-earth-32.heroku.com/stores with my application. Can anyone help with this?

@Kerde Please head on over to a new thread I made about that issue : https://teamtreehouse.com/forum/problem-in-the-getcontentlength-function?sort=my-posts

Ben solved it

Ben Jakuben
Ben Jakuben
Treehouse Teacher

It was a team effort with some help from some of our other students! :smile:

Thanks