php 輸出JSON格式,使用json_encode函數即可
例如:
<?phpheader('Content-type:?text/json');
$fruits?=?array?(
"fruits"?=>?array("a"?=>?"orange",?"b"?=>?"banana",?"c"?=>?"apple"),
"numbers"?=>?array(1,?2,?3,?4,?5,?6),
"holes"=>?array("first",?5?=>?"second",?"third")
);
echo?json_encode($fruits);
>得到結果:
{"fruits":{"a":"orange","b":"banana","c":"apple"},"numbers":[1,2,3,4,5,6],"holes":{"0":"first","5":"second","6":"third"}}