【发布时间】:2016-09-26 15:21:25
【问题描述】:
我将 JSON 数组作为字符串存储在 mysql 中
[{"id": 1, "mark": 5}, {"id": 2, "mark": 3}, {"id": 3, "mark": 2}]
当我尝试使用它时
@foreach ($places as $place)
@foreach ($place->rates as $rate)
{{var_dump($rate->marks)}}
@endforeach
@endforeach
有问题。 $rate->marks 是一个字符串。我应该如何将其解码为数组?
UPD
当然我尝试使用 json_decode,但它返回错误
htmlentities() expects parameter 1 to be string, array given
已解决
我,笨蛋。问题不在 json_decode 中。我尝试使用需要字符串作为参数的 {{ }} 打印结果。
【问题讨论】:
-
先解码json字符串,然后在foreach循环中使用。
-
使用
json_decode($rate->marks); -
@splash58 当然我尝试使用 json_decode,但它返回错误 htmlentities() Expects parameter 1 to be string, array given