【发布时间】:2019-06-30 02:32:37
【问题描述】:
我有包含这些数据的 json 列:
{
"address":"testing address, phone number, country, state, name of the person etc.",
"post_method":"tiki",
"post_price":"15000",
"weight":"2"
}
现在当我尝试在我的视图中返回这些数据时:
@foreach($order->shipment_data as $shipment) //shipment_data is the name of json column which holds this data
{{$shipment}}
@endforeach
它将address、post_method、post_price 和weight 下的所有数据一起返回,就像一个段落一样。
我无法分别获取每个部分,例如:
{{$shipment['post_price']}}
它返回:
非法字符串偏移'post_price'(查看:
有什么想法吗?
更新
{{dd($order->shipment_data)}}的结果
"{"address":"fake address here...","post_method":"tiki","post_price":"15000","weight":"2"} ◀"
【问题讨论】:
-
在 post_price 之前先添加索引 0
-
@aldrin27
Illegal string offset -
你需要
json_decode()数据吗? -
@OluwatobiSamuelOmisakin 建议先解码你的 json。
-
@OluwatobiSamuelOmisakin 我不这么认为,因为在我使用
json_encode存储我的数据之前,它在每个部分之前添加了 \ 然后我删除了该编码代码,所以现在它实际上只是保存了一个数组@ 987654333@ 我不认为我需要解码,只要我不编码它们
标签: php json laravel laravel-blade