zoukankan      html  css  js  c++  java
  • PHP生成json

    索引数组

    <?php
    //json_encode(数组/对象)
    $color = array('red','blue','green');
    echo json_encode($color); //["red","blue","green"]
    ?>

    关联数组

    <?php
    $animal = array('east'=>'tiger','north'=>'wolf','south'=>'monkey');
    echo json_encode($animal); //{"east":"tiger","north":"wolf","south":"monkey"}
    ?>

    json数组

    <?php
    $file_arr = array();//保存文件名
    $dir = dir("D:\input");//目录
    while($file = $dir->read()){//循环目录
        global $file_arr; //全局
        if($file !=".." && $file !="."){//判断不为返回上级
            $file_arr[] = $file;
        }
    }
    echo json_encode($file_arr); //["1.png","2.png"]
    ?>

    json关联数组

    <?php
    $animal = array();
    $animal['east'] = "tiger";
    $animal['north'] = "wolf";
    echo json_encode($animal); //{"east":"tiger","north":"wolf"}
    ?>
  • 相关阅读:
    Go--指针
    Go--struct
    Go--函数
    Go基础
    流程控制
    Go前言
    变量与常量
    Django(三):HttpRequest和HttpResponse
    Django(二):url和views
    tensorflow(一):图片处理
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709365.html
Copyright © 2011-2022 走看看