| 
                         $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)                         (编辑:莱芜站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |