gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:40:25 25 4
gpt4 key购买 nike

$array 的 var_dump 返回这个:

array (size=3)
0 =>
object(frontend\models\Notifications)[101]
private '_attributes' (yii\db\BaseActiveRecord) =>
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' (yii\db\BaseActiveRecord) =>
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' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
1 =>
object(frontend\models\Notifications)[108]
private '_attributes' (yii\db\BaseActiveRecord) =>
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,表的“文本”列也是如此。可能是什么问题?

最佳答案

您显示的数组具有所有私有(private)属性。这意味着该值在其类(class)范围之外不可用。

您可以查看此 SO 以获得一些建议

Using json_encode on objects in PHP (regardless of scope)

关于php - 为什么 json_encode 返回空括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34977148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com