加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

php – 为什么json_encode返回空括号?

发布时间:2021-04-01 02:39:55 所属栏目:编程 来源:网络整理
导读:$array的var_dump返回: array (size=3) 0 = object(frontendmodelsNotifications)[101] private '_attributes' (yiidbBaseActiveRecord) = array (size=5) 'id' = int 1 'created_on' = string '2015-11-12 12:12:15' (length=19) 'user_id' = int 1 't

$array的var_dump返回:

array (size=3)
  0 => 
    object(frontendmodelsNotifications)[101]
      private '_attributes' (yiidbBaseActiveRecord) => 
        array (size=5)
          'id' => int 1
          'created_on' => string '2015-11-12 12:12:15' (length=19)
          'user_id' => int 1
          'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
          'is_seen' => int 0
      private '_oldAttributes' (yiidbBaseActiveRecord) => 
        array (size=5)
          'id' => int 1
          'created_on' => string '2015-11-12 12:12:15' (length=19)
          'user_id' => int 1
          'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
          'is_seen' => int 0
      private '_related' (yiidbBaseActiveRecord) => 
        array (size=0)
          empty
      private '_errors' (yiibaseModel) => null
      private '_validators' (yiibaseModel) => null
      private '_scenario' (yiibaseModel) => string 'default' (length=7)
      private '_events' (yiibaseComponent) => 
        array (size=0)
          empty
      private '_behaviors' (yiibaseComponent) => 
        array (size=0)
          empty
  1 => 
    object(frontendmodelsNotifications)[108]
      private '_attributes' (yiidbBaseActiveRecord) => 
        array (size=5)
          'id' => int 2
          'created_on' => string '2015-11-12 12:12:15' (length=19)
          'user_id' => int 1
          'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
          'is_seen' => int 0
     ................................
     ................................
     ................................

但是json_encode($array)返回[{},{},{}].
我的尝试:
尝试将整个数据库的字符编码更改为utf8_general_ci.

我的表的字符编码是utf8_general_ci,因此表格的’text’列也是如此.可能是什么问题?

最佳答案 您显示的数组将所有属性设置为私有.这意味着该值在其类的范围之外是不可用的.

你可以看看这个SO的一些建议

Using json_encode on objects in PHP (regardless of scope)

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读