PHP Json_encode Multidimensional Associative Array
I've used php's json_encode() function many times, but for some reason I can't seem to find the problem here... Note: I've removed error checking for clarity purposes. //PHP
Solution 1:
Try and add:
header("Content-type: application/json; charset=utf-8");
Before you echo your JSON encoded result.
EDIT:
If the encoding doesn't work try the following:
while ($result = $stmt->fetch(PDO::FETCH_ASSOC))
{
$trows[] = array_map('utf8_encode', $result);
}
Solution 2:
I would see what PHP tells you:
Change
echo json_encode($trows);
to
$json = json_encode($trows);
$error = json_last_error();
if ($error !== JSON_ERROR_NONE) {
echo json_last_error_msg();
} else {
echo $json;
}
Post a Comment for "PHP Json_encode Multidimensional Associative Array"