當前位置:成語大全網 - 新華字典 - PHP是怎麽返回json格式的數據

PHP是怎麽返回json格式的數據

php 輸出JSON格式,使用json_encode函數即可

例如:

<?php

header('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"}}