json_decode使用注意事项
来源:互联网 发布:淘宝离职证明哪家靠谱? 编辑:程序博客网 时间:2024/06/08 09:00
json_decode — Decodes a JSON string
Description
mixed json_decode ( string $json [, bool $assoc ] )
Takes a JSON encoded string and converts it into a PHP variable.
Parameters
$json The json string being decoded.
$assoc When TRUE, returned objects will be converted into associative arrays.
Return Values
Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.
Description
mixed json_decode ( string $json [, bool $assoc ] )
Takes a JSON encoded string and converts it into a PHP variable.
Parameters
$json The json string being decoded.
$assoc When TRUE, returned objects will be converted into associative arrays.
Return Values
Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.
php中的json定义较之js更为严谨,遵守json的规范,所以熟练在js中使用并不等于可以在php中运用一样的规则,下面是需要注意的地方:
1、不能使用单引号来引pair,如
print_r(json_decode(’[0,{"a":"a","b":"b"},2,3]’)); //works
print_r(json_decode("[0,{’a':’a',’b':’b'},2,3]")); //doesn’t work
2、和js不一样,不允许末端有多余的逗号
print_r(json_decode(’[0,1 ]’)); //works
print_r(json_decode(’[0,1,]’)); //doesn’t work
3、pair中的键值也必须用双引号引起来
{ bar: “baz” } //js中这样写是可以的
{ “bar": “baz” } //php中必须要用双引号
4、Take care that json_decode() returns UTF8 encoded strings, whereas PHP normally works with iso-8859-1 characters.
$php_vlaues = utf8_decode(json_decode($somedata));
你可以使用json格式验证工具:
http://www.jsonlint.com/
- json_decode使用注意事项
- php中json_encode和json_decode使用注意事项
- json_decode使用
- json_decode使用
- json_decode
- php使用json_decode返回NULL
- php使用json_decode返回NULL
- json_encode与json_decode使用细节
- php使用json_decode返回NULL
- php使用json_decode返回NULL
- PHP使用json_decode转换unicode问题
- php使用json_decode解析json返回NULL
- php使用json_decode解析json返回NULL
- 使用json_decode()的一些小积累
- PHP POST获取的JSON使用json_decode返回NULL
- PHP POST获取的JSON使用json_decode返回NULL
- json_decode用法
- PHP json_decode
- SilkTest
- .htaccess文件
- linq To SQl之多表关联修改
- CCS2.2以后版本的GEL文件介绍
- linq To SQl之多表联合查询
- json_decode使用注意事项
- EJB开发体会
- 厚积薄发,有的放矢
- 搞笑:VC(风险投资)与泡妞的关系
- 数据结构学习笔记二 顺序表
- Spring-----> IOC(控制反转)
- 如何写个FLASH,上传到PHP管理系统啊
- MySQL 5.1.31编译安装
- 经典的三段论