json_decode与json_encode容易被忽视的点

一、json_decode的使用,json_decode共有4个参数

json_decode ( string $json [, bool $assoc=FALSE [, int $depth= 512 [, int $options= 0 ]]])

①:$json解析编码为UTF-8编码的字符串

②:$assoc:当该参数为 TRUE 时,将返回数组,FALSE 时返回对象

③:$depth 为递归深度

④:$options   JSON解码选项的位掩码。目前有两种支持的选项。第一个是JSON_BIGINT_AS_STRING允许将大整数转换为字符串而不是浮点数,这是默认值。第二个选项是JSON_OBJECT_AS_ARRAY ,它和设置相同的效果assoc来 TRUE

 

二:json_encode的使用,不转义中文汉字的方法

①:json_encode($data, JSON_UNESCAPED_UNICODE); //必须PHP5.4+ 

①:$array = array('lixi'=>'XX');  var_dump(json_encode($array,JSON_UNESCAPED_UNICODE));die;    打印得到  string(17) "{"lixi":"XX"}"

②:$array = array('lixi'=>'XX');  var_dump(json_encode($array));die;   打印得到  string(23) "{"lixi":"\u674e\u831c"}"

②:json_encode()只将索引数组(indexed array)转为数组格式,而将关联数组(associative array)转为对象格式

 

以上就是这次的全部内容!

posted @ 2018-08-27 11:28  静小妞  阅读(555)  评论(0编辑  收藏  举报