2016-07-30 3 views
0

json 객체를 만드는 방법은? 배열을 만들고 json_encode로 자동 완성 함수에 전달하고 싶습니다.PHP로 json 객체를 만드는 법

[ 
    {label:"Display Name for result 1", value:1}, 
    {label:"Display Name for result 2", value:2}, 
    {label:"Display Name for result 3", value:3} 
] 

답변

2

PHP는 json 자체를 사용하지 않습니다. 그냥 일반 PHP 배열을 만들고 json_encode 함수를 통해 그것을 밀어.

$stuff = array(
    array('label' => 'name 1', 'value' => 1), 
    array('label' => 'name 2', 'value' => 2), 
    array('label' => 'name 3', 'value' => 3), 
); 
echo json_encode($stuff); 
관련 문제