数据库json列返回Laravel刀片中的转义字符串 [英] Database json column returning escaped string in laravel blade
本文介绍了数据库json列返回Laravel刀片中的转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在MySQL列中保存了一些Json数据.在将数据获取到Laravel Blade应用程序时,所有json字段均被转义.因此,我在读取json数据时遇到问题.
I have saved some Json data in a MySQL column. While fetching the data to a Laravel Blade application the json fields are all escaped. Hence, I am facing issues while reading the json data.
[
{
"id": "1",
"json_backup": "{\"id\":\"2\",\"organization_id\":\"1\",\"amount\":\"7800.00\",\"date\":\"2015-05-11\",\"created_at\":\"2015-05-11 07:20:45\",\"updated_at\":\"2015-05-11 07:20:45\"}",
"ip": "127.0.0.1",
"created_at": "2015-05-12 12:21:16",
"updated_at": "2015-05-12 12:21:16"
}
]
上例中的json_backup字段被转义.如何确保不对该字段进行转义.
The json_backup field in the above example is escaped. How do I ensure that this field is not escaped.
获取数据的代码
$activity = Activity::find(1);
在视图中:
@foreach ($activities AS $activity)
@foreach($activity->json_backup AS $order)
@endforeach
@endforeach
错误:
为foreach()提供的参数无效
Invalid argument supplied for foreach()
任何帮助将不胜感激.
推荐答案
@saaz在JSON中存储JSON时,请使用
@saaz When you are storing the JSON in MySQL, use
json_encode($json_backup, JSON_UNESCAPED_SLASHES)
HTH
这篇关于数据库json列返回Laravel刀片中的转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文