
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tlug] Malformed UTF-8 in JSON?
- Date: Thu, 15 Jul 2010 06:44:50 +0900
- From: Dave M G <dave@example.com>
- Subject: [tlug] Malformed UTF-8 in JSON?
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100527 Thunderbird/3.0.5
TLUG,
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@example.com","timeout":"1279145273"}';
$myArray1 = json_encode($myData);
$myArray2 = utf8_encode (stripslashes($myArray1));
$myArray = json_decode($myArray2, true);
$jsonerror = json_last_error();
--
Dave M G
Home |
Main Index |
Thread Index