php编程学习笔记

来源:互联网 发布:手机相片编辑软件 编辑:程序博客网 时间:2024/05/21 09:11

1. Json:

问题:PHP Notice: Trying to get property of non-object

分析:出问题的代码行为:$num = count($result->people);

         $result的赋值行 $result = json_decode($data);

         一般情况下都不会有错误提示,可能是因为某些$data格式不对,无法解析为Json对象。

解决:使用$result前,先判断是否为null。

         if (isset($result)) $num = count($result->people);   //不能用if ($result == null)

0 0
原创粉丝点击