From f1d50b8a512c1c99e494799c96122462d152d5ce Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sun, 13 Oct 2019 00:21:20 +0900 Subject: [PATCH] Create json.format.php --- helper/json.format.php | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 helper/json.format.php diff --git a/helper/json.format.php b/helper/json.format.php new file mode 100644 index 0000000..9024901 --- /dev/null +++ b/helper/json.format.php @@ -0,0 +1,47 @@ + "json_decode", + "NO_FUNCTION_JSON_LAST_ERROR" => "json_last_error", + ); + $error = check_invaild_function($invalid_fn); + if($error < 0) { + if(array_key_equals("assoc", $options, true)) { + $obj = @json_decode($data, true); + } else { + $obj = @json_decode($data); + } + $result = (@json_last_error() === 0) ? $obj : $result; + } + + return $result; + } +} + +if(!check_function_exists("json_encode_ex")) { + function json_encode_ex($data, $options=array()) { + $result = false; + + if(array_key_equals("adaptive", $options, true)) { + // 2018-06-01: Adaptive JSON is always quotes without escape non-ascii characters + $lines = array(); + foreach($data as $k=>$v) { + if(is_array($v)) { + $lines[] = sprintf("\"%s\":%s", make_safe_argument($k), get_adaptive_json($v)); + } else { + $lines[] = sprintf("\"%s\":\"%s\"", make_safe_argument($k), make_safe_argument($v)); + } + } + $result = "{" . implode(",", $lines) . "}"; + } else { + $result = json_decode($data); + } + + return $result; + } +}