json_decode 지원 안될때 처리방법은? 정보
json_decode 지원 안될때 처리방법은?본문
php4에 그누보드 설치가 되어 있으며, 사정상 버전업을 할 수 없습니다.
그래서 그런지 json_decode가 지원이 안됩니다.
json.php 파일등을 통하여 json_decode 기능을 사용할 수 있을까요?
extend 폴더 등에 설치할 수 있는 지원파일 있으신 분 부탁드립니다.
*** 개인정보보호를 위한 이메일주소 노출방지 ***
그래서 그런지 json_decode가 지원이 안됩니다.
json.php 파일등을 통하여 json_decode 기능을 사용할 수 있을까요?
extend 폴더 등에 설치할 수 있는 지원파일 있으신 분 부탁드립니다.
*** 개인정보보호를 위한 이메일주소 노출방지 ***
댓글 전체
<?php
if (!function_exists('json_decode')) {
function json_decode($json) {
$comment = false;
$out = '$x=';
for ($i=0; $i<strlen($json); $i++) {
if (!$comment) {
if (($json[$i] == '{') || ($json[$i] == '[')) {
$out .= 'array(';
}
elseif (($json[$i] == '}') || ($json[$i] == ']')) {
$out .= ')';
}
elseif ($json[$i] == ':') {
$out .= '=>';
}
elseif ($json[$i] == ',') {
$out .= ',';
}
elseif ($json[$i] == '"') {
$out .= '"';
}
/*elseif (!preg_match('/\s/', $json[$i])) {
return null;
}*/
}
else $out .= $json[$i] == '$' ? '\$' : $json[$i];
if ($json[$i] == '"' && $json[($i-1)] != '\\') $comment = !$comment;
}
eval($out. ';');
return $x;
}
}
?>
출처 : http://php.net/manual/en/function.json-decode.php
if (!function_exists('json_decode')) {
function json_decode($json) {
$comment = false;
$out = '$x=';
for ($i=0; $i<strlen($json); $i++) {
if (!$comment) {
if (($json[$i] == '{') || ($json[$i] == '[')) {
$out .= 'array(';
}
elseif (($json[$i] == '}') || ($json[$i] == ']')) {
$out .= ')';
}
elseif ($json[$i] == ':') {
$out .= '=>';
}
elseif ($json[$i] == ',') {
$out .= ',';
}
elseif ($json[$i] == '"') {
$out .= '"';
}
/*elseif (!preg_match('/\s/', $json[$i])) {
return null;
}*/
}
else $out .= $json[$i] == '$' ? '\$' : $json[$i];
if ($json[$i] == '"' && $json[($i-1)] != '\\') $comment = !$comment;
}
eval($out. ';');
return $x;
}
}
?>
출처 : http://php.net/manual/en/function.json-decode.php
답변감사합니다. 출처도 가보고 적용해 보고 있습니다. 아직 해결이 안되네요.
json_decode($result, true); 함수가 필요한데
Fatal error: Call to undefined function: json_decode() in... 이 발생합니다.
json_decode($result, true); 함수가 필요한데
Fatal error: Call to undefined function: json_decode() in... 이 발생합니다.
