laravel- json_decode返回阵列,但无法在laravel 9中回荡数组值

发布于 2025-01-22 00:47:40 字数 543 浏览 1 评论 0原文

因此,我的数据库中有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪 2025-01-29 00:47:40

我得到了答案。这不是错误或其他东西。问题发生了,因为我在数据库表中有三行。 其中只有一个具有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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文