01-18-2008, 05:00 PM
|
#1 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Json_encode is crazy
To cut a long story short, I'm wanting to check the return value of the json_encode function - therefore if its false I can throw an exception. What do I find? The lovely json_encode returns false as a string if it fails!
php Code:
$aJson = json_encode($szContent);
if(!$aJson) { throw new Exception('Badly formatted JSON returned'); }
That won't work because it's a string, and I can't typecast it using (bool) because the string will be seen as a true value. Here's the result from var_dump when json_encode fails:
Does anybody have any idea? I don't want to just do it like the following as that would be very silly indeed.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|