From: hm2k Operating system: PHP version: 5.3.5 Package: JSON related Bug Type: Bug Bug description:Failed to decode, yet json_last_error() is JSON_ERROR_NONE
Description: ------------ I'm trying the json_decode() function on real world strings, not just from strings produced using json_encode(). I have included the test case from bug #52262 as well to show that this issue is different. Thanks. Test script: --------------- <pre> <?php /* Settings */ /* from http://dealerservices.autotrader.co.uk/14184/cars.htm */ $urls[]='http://atsearch.autotrader.co.uk/js/uvl/InlineServlet.js?did=14184&configfile=http://dealerservices.autotrader.co.uk/dealers/14184/14184_config.xml&csslocation=http://dealerservices.autotrader.co.uk/dealers/14184/14184&dropdowntype=uvl&partner=TMG&postcode=me86ad&miles=1500&sort=5&action=searchresults'; /* from http://api.jquery.com/jQuery.getJSON/ */ $urls[]='http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=jQuery15094986786483787_1297190250272&tags=cat&tagmode=any&format=json&_=1297190250280'; /* from http://code.google.com/apis/base/samples/javascript/tutorial.html */ $urls[]='http://www.google.com/base/feeds/attributes/-/vehicles?max-values=30&bq=[target%20country:GB]&alt=json-in-script&callback=showMake'; /* from http://code.google.com/apis/gdata/docs/json.html */ $urls[]='http://www.google.com/calendar/feeds/developer-calen...@google.com/public/full?alt=json'; /* from http://code.google.com/apis/gdata/docs/json.html */ $urls[]='http://www.google.com/calendar/feeds/developer-calen...@google.com/public/full?alt=json-in-script&callback=myFunction'; /* from http://bugs.php.net/bug.php?id=52262 */ $urls[]='http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0001/?gameid=440'; /* from http://php.net/manual/en/function.json-last-error.php */ $json_errors=array( -1 => 'An unknown error occured', JSON_ERROR_NONE => 'No error has occurred', JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', JSON_ERROR_SYNTAX => 'Syntax error', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'); /* main loop */ foreach($urls as $url) { echo PHP_EOL; //call the json $json=file_get_contents($url); echo 'Decoding... ' . $url . PHP_EOL; //convert from jsonp to json $json=preg_replace('/.+?({.+}).+/','$1',$json); //get a result $result=json_decode($json); if ($result) { echo 'Decoded.'; } else { echo 'Failed to decode.'; } echo PHP_EOL; $err=json_last_error(); if ($err != JSON_ERROR_NONE) { echo 'Error: '; echo isset($json_errors[$err])?$json_errors[$err]:$json_errors[-1]; } else { echo 'No error.'; } echo PHP_EOL; } //eof Expected result: ---------------- The first result should either: * Decode successfully and have no error (preferable) Or * Fail to decode and have an error which explains why Actual result: -------------- Decoding... http://atsearch.autotrader.co.uk/js/uvl/InlineServlet.js? did=14184&configfile=http://dealerservices.autotrader.co.uk/dealers/14184/14184_ config.xml&csslocation=http://dealerservices.autotrader.co.uk/dealers/14184/1418 4&dropdowntype=uvl&partner=TMG&postcode=me86ad&miles=1500&sort=5&action=searchre sults Failed to decode. No error. Decoding... http://api.flickr.com/services/feeds/photos_public.gne? jsoncallback=jQuery15094986786483787_1297190250272&tags=cat&tagmode=any&format=j son&_=1297190250280 Failed to decode. Error: Syntax error Decoding... http://www.google.com/base/feeds/attributes/-/vehicles?max- values=30&bq=[target%20country:GB]&alt=json-in-script&callback=showMake Decoded. No error. Decoding... http://www.google.com/calendar/feeds/developer- calen...@google.com/public/full?alt=json Decoded. No error. Decoding... http://www.google.com/calendar/feeds/developer- calen...@google.com/public/full?alt=json-in-script&callback=myFunction Decoded. No error. Decoding... http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForAp p/v0001/?gameid=440 Decoded. No error. -- Edit bug report at http://bugs.php.net/bug.php?id=53963&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53963&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53963&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53963&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53963&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53963&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53963&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53963&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53963&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53963&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53963&r=support Expected behavior: http://bugs.php.net/fix.php?id=53963&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53963&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53963&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53963&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53963&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53963&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53963&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53963&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53963&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53963&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53963&r=mysqlcfg