深圳全飞鸿
标题:
php返回json格式的内容
[打印本页]
作者:
zhgc
时间:
2019-7-11 14:38
标题:
php返回json格式的内容
本帖最后由 zhgc 于 2019-7-11 14:41 编辑
get:
<?php
header('Content-type: text/json');
$fruits = $_GET;
echo json_encode($fruits);
?>
复制代码
server:
<?php
header('Content-type: text/json');
$fruits = $_SERVER;
echo json_encode($fruits);
?>
复制代码
post:
<?php
header('Content-type: text/json');
$fruits = $_POST;
echo json_encode($fruits);
?>
复制代码
作者:
zhgc
时间:
2019-7-11 14:40
<?php
header('Content-type: text/json;charset=utf-8');
$fruits = array (
"fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "中文")
);
echo json_encode($fruits,JSON_UNESCAPED_UNICODE);
?>
复制代码
欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/)
Powered by Discuz! X3.2