laravel- json_decode返回阵列,但无法在laravel 9中回荡数组值
因此,我的数据库中有一个JSON数据,如下所示: -
$json = ["16502735051.jpg","16502735052.jpg","16502735053.jpg","16502735055.jpg"];
现在,我将此JSON解码为以下类似的数组: -
$arr = json_decode($json);
当我使用print_r打印此arr时,它将返回如下: -
Array ( [0] => 16502735051.jpg [1] => 16502735052.jpg [2] => 16502735053.jpg [3] => 16502735054.jpg [4] => 16502735055.jpg )
当我尝试从大批。我写这篇文章: -
echo $arr[0]
返回错误。显示: - 尝试访问null类型的值的值偏移量
So I have a Json data in my Database like below:-
$json = ["16502735051.jpg","16502735052.jpg","16502735053.jpg","16502735055.jpg"];
Now I decoded this JSON into an Array like below:-
$arr = json_decode($json);
when I print this arr using print_r it returns as below:-
Array ( [0] => 16502735051.jpg [1] => 16502735052.jpg [2] => 16502735053.jpg [3] => 16502735054.jpg [4] => 16502735055.jpg )
The prob occurs when I try to get the value from the array. I write this:-
echo $arr[0]
It return error. Shows:- Trying to access array offset on value of type null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了答案。这不是错误或其他东西。问题发生了,因为我在数据库表中有三行。 其中只有一个具有JSON值。这就是为什么其他行返回
null
此Laravel返回致命错误并停止脚本的原因。I got the answer. It's not a bug or something. The problem was happening because, I have three rows in the DB table. Only one of them has Json Value. That's why other rows were returning
null
this Laravel returned Fatal error and stopped the script.