View Single Post
Old 01-18-2008, 06:47 PM   #10 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Well, json_encode will only return "null" in two cases:
  1. If the argument passed in was NULL.
  2. 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)
        ));
    } 
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Wildhoney (01-18-2008)