php - 无法从 json_encoded 数组中获取数据
问题描述
我有关键和价值数据。键是一个数组。我想foreach这个关键数据。我使用 laravel 5。我的 json_decoded 数组如下:
Collection {#1288 ▼
#items: array:4 [
"{"id":1,"title":"abc","path":"abc-path"}" => 19
]
}
但我无法像我想要的代码那样获取关键数据:
@foreach($trendings as $key => $value)
{{ $key->id }}
@endforeach
它给出了“尝试获取非对象的属性”错误。但是如果编写如下代码:
@foreach($trendings as $key => $value)
{{ $key }}
@endforeach
它给了我
{"id":1,"title":"abc","path":"abc-path"}
但我希望它们在我的 html 中使用。我怎样才能拿到它们?
解决方案
In my opinion, view should not execute a json_decode. I expect view to get already decoded variables, i think that if your data is not completly decoded something is missing before the view.
Of course i would rather work on fixing what's wrong before than patching your view.
推荐阅读
- groovy - 如何在 Groovy 中修复“无法将类 MultipartFormEntity 的对象转换为 HttpEntity”错误
- python-3.x - python和mysql工作台中两个日期的区别
- kivy - 如何处理 Kivy FileChooserController 的 FileNotFoundError 异常
- java - 一个 jar 文件执行,但另一个 jar 不会执行
- laravel - 找不到网址,请点击 gmail 中的密码重置链接
- windows - 当Windows以平板电脑模式启动时如何运行批处理文件
- java - 使用牛顿法求平方根的时间复杂度
- node.js - npm install 总是卡在那个确切的时间
- python - 如何有效地将系列索引添加到 Pandas 系列列表数组的每个列表元素?
- centos - 错误:在 1556435360(unix 时间)中止,如果您使用 GNU date #6760,请尝试“date -d @1556435360”