-- 创造无限可能

php开发:JSON相关函数和功能

2022-06-26 16:08:51
593 人浏览 2 人点赞
有用,点赞支持一下

相关函数

json_encode($data);//对变量进行JSON编码
json_decode($data,true)//对JSON格式的字符串进行解码
json_last_error();//返回最后一次反生的错误

基础用法

  1. json_decode
     //mixed json_decode ( string $json [, bool $assoc ] )
     //json待解码的 json string 格式的字符串。
     //assoc当该参数为 TRUE 时,将返回array而非 object 。默认false
     $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
     var_dump(json_decode($json));
     var_dump(json_decode($json, true));