I want to pass the result of a mysql query out as JSON in PHP 5.6.3. The data contains non alphanumeric characters, particularly in this case the 'degrees' symbol (as in '45º').
json_encode
seems to fail silently if the data contains such characters:
$json = json_encode($my_obj);
I can make the encode step work by using utf8_encode
on the offending properties:
$my_obj->description = utf8_encode($my_obj->description);
...but then I get output like this: '45º' which is not desirable.
The database table uses UTF-8 Unicode encoding (utf_unicode_ci) and the data appears to be stored and retrieved successfully. It just breaks json_encode
when it finds these characters.
How to solve this?