I want to return multiple responses from PHP to my Android device.
In PHP I have something like:
while ($row = mysql_fetch_array($data)) {
$response["post"] = strip_tags($row["post_text"]);
$response["date"] = date('D M d, Y', $row["post_time"]);
echo json_encode($response);
}
In Logcat I get:
{“tag”:”midnightAnnouncements”,”success”:1,”error”:0,”post”:”This is a test announcement! “,”date”:”Sun Oct 21, 2012″}{“tag”:”midnightAnnouncements”,”success”:1,”error”:0,”post”:”Here is another “,”date”:”Sun Oct 21, 2012″}n
These are the results of two rows. I’d like to iterate over the JSON object and get the strings for both “post”s. How can this be done in Java?
You can wrap the output in a JSON array: