Update json.format.php
This commit is contained in:
parent
6713e2f654
commit
07c362cb15
|
@ -5,6 +5,8 @@
|
||||||
if(!check_function_exists("json_decode_ex")) {
|
if(!check_function_exists("json_decode_ex")) {
|
||||||
function json_decode_ex($data, $options=array()) {
|
function json_decode_ex($data, $options=array()) {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
|
$is_assoc = array_key_equals("assoc", $options, true);
|
||||||
|
|
||||||
$invalid_fn = array(
|
$invalid_fn = array(
|
||||||
"NO_FUNCTION_JSON_DECODE" => "json_decode",
|
"NO_FUNCTION_JSON_DECODE" => "json_decode",
|
||||||
|
@ -13,8 +15,11 @@ if(!check_function_exists("json_decode_ex")) {
|
||||||
$error = check_invalid_function($invalid_fn);
|
$error = check_invalid_function($invalid_fn);
|
||||||
|
|
||||||
if($error < 0) {
|
if($error < 0) {
|
||||||
$_result = array_key_equals("assoc", $options, true) ? @json_decode($data, true) : @json_decode($data);
|
if($is_assoc) {
|
||||||
$result = (@json_last_error() === 0) ? $_result : $result;
|
$result = json_decode($data, true);
|
||||||
|
} else {
|
||||||
|
$result = json_decode($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -26,7 +31,6 @@ if(!check_function_exists("json_encode_ex")) {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
$is_adaptive = array_key_equals("adaptive", $options, true);
|
$is_adaptive = array_key_equals("adaptive", $options, true);
|
||||||
$is_assoc = array_key_equals("assoc", $options, true);
|
|
||||||
|
|
||||||
if($is_adaptive) {
|
if($is_adaptive) {
|
||||||
// 2018-06-01: Adaptive JSON is always quotes without escape non-ascii characters
|
// 2018-06-01: Adaptive JSON is always quotes without escape non-ascii characters
|
||||||
|
@ -39,8 +43,6 @@ if(!check_function_exists("json_encode_ex")) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result = "{" . implode(",", $lines) . "}";
|
$result = "{" . implode(",", $lines) . "}";
|
||||||
} elseif($is_assoc) {
|
|
||||||
$result = json_encode($data, true);
|
|
||||||
} else {
|
} else {
|
||||||
$result = json_encode($data);
|
$result = json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user