Malformed UTF-8 Data in JSON
| From: | Dave M G | Date: | Wed, 14 Jul 2010 23:13:46 +0000 |
| Subject: | Malformed UTF-8 Data in JSON | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-306896@lists.php.net to get a copy of this message | ||
PHP Users,
I'm decoding some JSON data in PHP to convert it into an array.
However, it's not working, and json_last_error() is returning a value of "4", which I believe means "Malformed UTF-8 characters, possibly incorrectly encoded".
I try at every turn in every setting to ensure that all my code and connections are in UTF-8.
But how can I be sure it's valid UTF-8? I've tried using the PHP command utf8_encode() on the string, but that hasn't changed anything.
And can I trust the error message?
Any help or advice would be much appreciated.
By the way, here is the code I'm currently testing with. I'm just encoding and then decoding a string right in the PHP just to get it to work before I even try getting the data from anywhere else.
$myData ='{"display_name":"Test
Guy","email":"testguy@testaddress.com","timeout":"1279145273"}';
$myArray1 = json_encode($myData);
$myArray2 = utf8_encode (stripslashes($myArray1));
$myArray = json_decode($myArray2, true);
$jsonerror = json_last_error();
--
Dave M G