Android Question How to get an array using okhttputils2

saeed10051

Active Member
Licensed User
Longtime 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
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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.
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime 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
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime 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
 
Upvote 0

udg

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

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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.

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0

martha

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

and replace with

PHP:
$res = json_encode($rows);

jason_encode has an extra "a".
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime 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.
 
Upvote 0
Top