json_encode()
wont work for me when I\'m using åäö. Why? And how can I get it to work?
The php
:
echo json_encode($arr);
Using the standard method when reading from MySQL:
$resultArray = array();
while($obj = MySQL_fetch_object($res)) {
$resultArray[] = $obj;
}
$result = json_encode($resultArray);
The encoding can be done using the following:
$resultArray = array();
while($obj = MySQL_fetch_object($res)) {
foreach($obj as $key => $value) {
if (!is_null($value)) {
$obj->$key = utf8_encode($value);
}
}
$resultArray[] = $obj;
}
$result = json_encode($resultArray);
The if is_null
has to be included so that null fields (e.g., DateTime fields) remain null in the output.