深圳全飞鸿

标题: php返回json格式的内容 [打印本页]

作者: zhgc    时间: 2019-7-11 14:38
标题: php返回json格式的内容
本帖最后由 zhgc 于 2019-7-11 14:41 编辑

get:

  1. <?php

  2. header('Content-type: text/json');

  3. $fruits = $_GET;
  4. echo json_encode($fruits);

  5. ?>
复制代码



server:

  1. <?php
  2. header('Content-type: text/json');
  3. $fruits = $_SERVER;
  4. echo json_encode($fruits);
  5. ?>
复制代码



post:

  1. <?php
  2. header('Content-type: text/json');
  3. $fruits = $_POST;
  4. echo json_encode($fruits);
  5. ?>
复制代码

作者: zhgc    时间: 2019-7-11 14:40
  1. <?php
  2. header('Content-type: text/json;charset=utf-8');
  3. $fruits = array (
  4.     "fruits"  => array("a" => "orange", "b" => "banana", "c" => "apple"),
  5.     "numbers" => array(1, 2, 3, 4, 5, 6),
  6.     "holes"   => array("first", 5 => "second", "中文")
  7. );
  8. echo json_encode($fruits,JSON_UNESCAPED_UNICODE);
  9. ?>
复制代码





欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2