From 04978bc31b4e9ae0aa621890321bdaf7fb6bc550 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 7 Sep 2016 12:56:09 +0000 Subject: [PATCH] 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 --- outputjson.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/outputjson.php b/outputjson.php index 6b629f7..48871f7 100644 --- a/outputjson.php +++ b/outputjson.php @@ -4,7 +4,9 @@ @author Dominique Fournier */ 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; }