2019-10-12 15:21:20 +00:00
|
|
|
<?php
|
2019-10-12 15:27:19 +00:00
|
|
|
// @date 2019-10-13
|
|
|
|
// @author Go Namhyeon <gnh1201@gmail.com>
|
2019-10-12 15:21:20 +00:00
|
|
|
|
|
|
|
if(!check_function_exists("json_decode_ex")) {
|
|
|
|
function json_decode_ex($data, $options=array()) {
|
|
|
|
$result = false;
|
|
|
|
|
|
|
|
$invalid_fn = array(
|
|
|
|
"NO_FUNCTION_JSON_DECODE" => "json_decode",
|
|
|
|
"NO_FUNCTION_JSON_LAST_ERROR" => "json_last_error",
|
|
|
|
);
|
|
|
|
$error = check_invaild_function($invalid_fn);
|
2019-10-12 15:29:07 +00:00
|
|
|
|
2019-10-12 15:21:20 +00:00
|
|
|
if($error < 0) {
|
2019-10-12 15:29:07 +00:00
|
|
|
$_result = array_key_equals("assoc", $options, true) ? @json_decode($data, true) : @json_decode($data);
|
|
|
|
$result = (@json_last_error() === 0) ? $_result : $result;
|
2019-10-12 15:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2019-10-15 11:45:32 +00:00
|
|
|
$result = json_encode($data);
|
2019-10-12 15:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|