Android Question How to get an array using okhttputils2

saeed10051

Active Member
Licensed User
I am using following php script and it is returning an array to me. How can i get the data out of this array as i am using j as httpjob, but httpjob does not have a get array type of method.

$result = $conn->query("SELECT * FROM menuitems");

if ($result->num_rows > 0) {
$rows = array();
while($r = $result->fetch_assoc()) {
$rows[] = $r;
}
} else {
echo "0 results";
}
echo $rows;
$result->close();

i want trying to convert the array to string using json on the php script side but it is giving me error as json is not supported on the domain where my php script is running
 

aeric

Well-Known Member
Licensed User
Use echo json_encode()
 

DonManfred

Expert
Licensed User
i tried that already, but it is giving me error on the server side
WHERE is the errormessage? <-- !!
it seems that server does not recognize json
Your app gets the echo output. So it must be your app which must be able to read the json from your server.

You are NOT giving any useful information to us to help you.
 

saeed10051

Active Member
Licensed User
WHERE is the errormessage? <-- !!

Your app gets the echo output. So it must be your app which must be able to read the json from your server.

You are NOT giving any useful information to us to help you.
when i am using following code
if ($result->num_rows > 0) {
// output data of each row
$rows = array();
while($r = $result->fetch_assoc()) {
$rows[] = $r;
}
} else {
echo "0 results";
}
$res = jason_encode($rows);
echo $res;
$result->close();

$conn->close();
?>
i am getting following error on running it in the browser
Connected to the database.

Fatal error: Uncaught Error: Call to undefined function jason_encode() in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php:24 Stack trace: #0 {main} thrown in /srv/disk20/3373050/www/saeedhassan.atwebpages.com/r.php on line 24

$res = jason_encode($rows); is on line 24
 

saeed10051

Active Member
Licensed User
However if i run following code
if ($result->num_rows > 0) {
// output data of each row
$rows = array();
while($r = $result->fetch_assoc()) {
$rows[] = $r;
}
} else {
echo "0 results";
}
//$res = jason_encode($rows);
echo $rows;
$result->close();

$conn->close();
?>

i get following result on browser

Connected to the database.
Array
 

udg

Expert
Licensed User
What's in your real code, jason_encode or json_encode?
 

DonManfred

Expert
Licensed User
Last edited:

DonManfred

Expert
Licensed User
if ($result->num_rows > 0) {
// output data of each row
$rows = array();
while($r = $result->fetch_assoc()) {
$rows[] = $r;
}
} else {
echo "0 results";
}
$res = jason_encode($rows);
echo $res;
$result->close();

$conn->close();
?>
Also

Please use [CODE]code here...[/CODE] tags when posting code.



 

martha

Member
Check this line
PHP:
$res = jason_encode($rows);
and replace with

PHP:
$res = json_encode($rows);
jason_encode has an extra "a".
 

saeed10051

Active Member
Licensed User
Check this line
PHP:
$res = jason_encode($rows);
and replace with

PHP:
$res = json_encode($rows);
jason_encode has an extra "a".
Thanks All,
yes this was the mistake one extra a was screwing everything. It is working now.
 
Top