outputjson : display an error message if the json to display is invalid (binary)

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3028 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-09-07 12:56:09 +00:00
parent b5b01032ae
commit 04978bc31b

View File

@@ -4,7 +4,9 @@
@author Dominique Fournier <dominique@fournier38.fr> */
require_once ("output.php");
/** Display in JSOn the data provided */
/** Display in JSON the data provided
* The data must NOT be binary !
*/
class outputjson extends output
{
/** Don't allow to output in JSON if the functions are not available in PHP */
@@ -25,7 +27,11 @@ class outputjson extends output
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header ("Content-Type: application/json");
echo json_encode ($data);
$content = json_encode ($data);
if (json_last_error () !== 0)
printf (dgettext("domframework", "Can't send in JSON invalid data : %s"),
json_last_error_msg ());
echo $content;
if (!defined ("PHPUNIT"))
exit;
}