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

inputstream empty with my own JSON

I've been trying to take the blog reader project and see if I could use my own JSON data however the inputstream is always comes back empty when I use my own.

I created a quick PHP script to produce some JSON that I think is valid: http://www.txtsource.com/api.php You can see it wants to give an array of Book, Chapter, Text

However, using the exact same code as the blog reader project the inputstream always seems to be empty (I've tried checking it with inputStream.available())

However, the exact same code gives content with the project's original http://blog.teamtreehouse.com/api/get_recent_summary

Am I encoding the JSON incorrectly?

The PHP is:

<?php header("Content-type: text/html; charset=utf-8"); 

$result = mysql_query($sql,$link) or die("Unable to select: ".mysql_error());

$books = array("books"=>array());

while ($row = mysql_fetch_array($result)) {
    $bookRow = array(
        "book"=>$row["book"],
        "chapter"=>$row["chapter"],
        "text"=>$row["text"]
    );
    array_push($books["books"], $bookRow);
}

header('Content-type: application/json');
echo json_encode($books);

mysql_close($link);

?>

Not sure if it appropriate to ask this here but thanks a lot if anyone has any ideas.

1 Answer

I found the answer was already on the forum: https://teamtreehouse.com/forum/trying-to-retrieve-data-from-my-own-blog-help

Sorry I missed it and thanks Ben / Vivek for the solution.