Update json.format.php

This commit is contained in:
Namhyeon Go 2020-01-14 11:28:39 +09:00 committed by GitHub
parent fc9459f814
commit 6713e2f654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,8 +24,11 @@ if(!check_function_exists("json_decode_ex")) {
if(!check_function_exists("json_encode_ex")) {
function json_encode_ex($data, $options=array()) {
$result = false;
$is_adaptive = array_key_equals("adaptive", $options, true);
$is_assoc = array_key_equals("assoc", $options, true);
if(array_key_equals("adaptive", $options, true)) {
if($is_adaptive) {
// 2018-06-01: Adaptive JSON is always quotes without escape non-ascii characters
$lines = array();
foreach($data as $k=>$v) {
@ -36,10 +39,12 @@ if(!check_function_exists("json_encode_ex")) {
}
}
$result = "{" . implode(",", $lines) . "}";
} elseif($is_assoc) {
$result = json_encode($data, true);
} else {
$result = json_encode($data);
}
return $result;
}
}