美文网首页
PHP是怎么返回json格式的数据

PHP是怎么返回json格式的数据

作者: 溢之 | 来源:发表于2016-12-22 11:15 被阅读0次

php 输出JSON格式,使用json_encode函数即可

例如:

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")

);

echojson_encode($fruits);

?>

得到结果:

{"fruits":{"a":"orange","b":"banana","c":"apple"},"numbers":[1,2,3,4,5,6],"holes":{"0":"first","5":"second","6":"third"}}

相关文章

网友评论

      本文标题:PHP是怎么返回json格式的数据

      本文链接:https://www.haomeiwen.com/subject/whwcvttx.html