2010년 3월 11일 목요일

JSON-PHP란?

JSON-PHP는 JSON 정보의 인코딩과 디코딩을 쉽게 해 주는 PHP 유틸리티이다.

http://mike.teczno.com/json.html 에서 무료로 구할 수 있다.

PHP에서 JSON 객체를 이용하기 위해 필요한 일은 페이지에 JSON.php 파일을 포함시켜서 JSON 객체를 이용하는 것뿐이다.

JSON 객체의 새로운 인스턴스를 생성하는 방법은 아주 간단하다.

 

<?php
require_once("JSON.php");
$oJSON = new JSON();
?>


==========

In Javascript, consuming input in JSON format is as easy as:

eval("var decoded_data = "+encoded_data);

 

 

With JSON-PHP, it can be almost as easy on the server-side, too:

// create a new instance of Services_JSON
require_once('JSON.php');
$json = new Services_JSON();

// convert a complex value to JSON notation
$value = array(1, 2, 'foo');
$output = $json->encode($value);
print($output);

// accept incoming POST data
$input = $GLOBALS['HTTP_RAW_POST_DATA'];
$value = $json->decode($input);

 

댓글 없음:

댓글 쓰기