尝试将包含html标记的json数据加载到html文件中

时间:2017-11-25 17:10:26

标签: php html json

我有一个包含HTML标记的正文的json响应:

{
    "total": 15,
    "per_page": 15,
    "current_page": 1,
    "last_page": 1,
    "next_page_url": null,
    "prev_page_url": null,
    "from": 1,
    "to": 15,
    "data": [
        {
            "id": 48,
            "title": "Lamb Ribs with mashed potatoes",
            "body": "<p>Lamb Ribs with Mashed Potatoes:<br />230 grams of lamb ribs<br />Marinade:( Teaspoon pomegranate molasses, 1 tablespoon lemon juice, 1 teaspoon tomato paste, 1 teaspoon olive oil, salt, black pepper, &nbsp;oregano)<br />Marinate the ribs for at least 2 hours. &nbsp;Heat a non stick grilling skillet and grill the ribs from both sides untill done.<br /><br />Mashed Potatoes:<br />130 grams of peeled potatoes. Boil until cooked and let to cool.<br />Add a tablespoon of milk, salt, garlic powder and black pepper and mash together.<br />Serve immediately.<br /><br />545 calories<br />24.7 g fat<br />29.8 g carb<br />3.1 g fiber<br />48.3 g protein<br />.</p>",
            "excerpt": "",
            "format": "standard",
            "type": "recipe",

注意:上面的json没有填满,因为它的响应文件很长。

我已解码上面的json:

$post = json_decode($response);

在视图文件中:

{{$post->body}}

文本已加载,但未将其格式化为标记。 enter image description here

在视图源/ chrome中,它显示如下: - enter image description here

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

使用: -

解决
{!! $text !!}