Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.