0

I have a function that return a list of cities (and some other data)

//after some logic
print_r($cities);
echo json_encode($cities);

Result of print_r after retreving one city, in this case Medellín city:

Array ( [0] => Array ( [id] => 1 [state_id] => 2 [name] => Medellín [propauthor] => 0 ) )

But the json_encode() just returns false

EDIT: json_last_error () returns JSON_ERROR_UTF8, as you can see cities might have tildes (accents)

6

1 Answer 1

2

From PHP's manpage for json_last_error():

JSON_ERROR_UTF8 Malformed UTF-8 characters, possibly incorrectly encoded (PHP 5.3.3)

You have to ensure that the data given to json_encode() is UTF8, you should try using iconv to convert your strings to a proper format.

1
  • 1
    Well, Changed the MySQL Tables to handle UTF-8 Instead of 'latin1_swedish_ci' now the result set is reaching json_encode properly encoded to UTF-8. It's working Feb 24, 2015 at 13:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.