Top

php 5.2 버전 이하에서 json 사용하기 | Web-Programing
신장미 (shinjm) | Text | 2013/02/13 19:59:50 | 조회:3764
첨부파일 (2)

# 사용법
1. json_decode 함수 선언
2. 클래스 생성
3. decode 하기



json.php 파일을 include 한 후에 ! 클래스를 선언합니다.

$test = new Services_JSON();
변수명 = $test->decode(decode할 값, true);

이렇게 사용하면 되는데 ! 
but... object를 못읽으므로 함수를 추가합니다 ! 

★ 클래스 선언한 부분 위에 함수를 추가해 주세요 !

if ( !function_exists('json_decode') ){
             function json_decode($json) 
	{  
		// Author: walidator.info 2009 
		$comment = false; 
		$out = '$x='; 
		
		for ($i=0; $i<strlen($json); $i++) 
		{ 
			if (!$comment) 
			{ 
				if ($json[$i] == '{')        $out .= ' array('; 
				else if ($json[$i] == '}')    $out .= ')'; 
				else if ($json[$i] == ':')    $out .= '=>'; 
				else                        $out .= $json[$i];            
			} 
			else $out .= $json[$i]; 
			if ($json[$i] == '"')    $comment = !$comment; 
		} 
		eval($out . ';'); 
		return $x; 
	}
}
공유하기
공유하기
0
0
0


댓글을 불러오는 중입니다.
▲ 이전글 [Oracle] 클라이언트 설치 진기원 (jjinki) 2013-02-14 18:30:32
▼ 다음글 [PHP] 한글 문자열 자르기 이강현 (lkhtt) 2013-02-12 18:58:24