01-18-2008, 06:47 PM
|
#10 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Well, json_encode will only return "null" in two cases: - If the argument passed in was
NULL.
- If the argument passed is not JSON encodable.
Therefore, a quick check for errors might be something along the lines of the following :
PHP Code:
// Suppress E_WARNING error if any.
$szJson = @json_encode($szContent);
// If the encoded string is "null" but we didn't pass in NULL
// then throw the exception.
if ($szJson === 'null' AND $szContent !== NULL)
{
throw new Exception(sprintf(
'Unable to encode "%s" into JSON format.',
gettype($szContent)
));
}
|
|
|
|