如何在没有引号的情况下获得我的数组结果

我在表中获取了我的数据 我有一个数组作为我想要的字符串存储,当我获取这些数据时,我没有用 '""' 获取它,第二个问题我用 slaches 获取它!就像功能主义者一样。这是我得到的


  {

        "id": 1,

        "icon": "/lsapp/public/projects/icon/1558102023logoMazad.png",

        "descriptions": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",

        "fonctionnalites": "[\"CreativeDesign\",\"RetinaReady\",\"ModernDesign\",\"DigitalMarketingBranding\",\"rcveq\"]",

        "screenshoot": "[\"/lsapp/public/projects/screenshoot/1558102023mazad1.png\",\"/lsapp/public/projects/screenshoot/1558102023mazad2.png\",\"/lsapp/public/projects/screenshoot/1558102023mazad3.png\",\"/lsapp/public/projects/screenshoot/1558102023mazad4.png\"]",

    },

我想要这样


  {

        "id": 1,

        "icon": "/lsapp/public/projects/icon/1558102023logoMazad.png",

        "descriptions": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris ",

        "fonctionnalites": ["CreativeDesign","RetinaReady","ModernDesign","DigitalMarketingBranding","rcveq"],

        "screenshoot": ["/lsapp/public/projects/screenshoot/1558102023mazad1.png\","/lsapp/public/projects/screenshoot/1558102023mazad2.png","/lsapp/public/projects/screenshoot/1558102023mazad3.png","/lsapp/public/projects/screenshoot/1558102023mazad4.png"],

    },

这就是我为得到结果所做的


public function getproject(Request $request)

{

    $services = WebProjects::all();

    return response()->json($services);

}


慕斯709654
浏览 145回答 2
2回答

潇湘沐

看来您的成员fonctionnalites和screenshoot已经是 json 编码的。// in this example, the sub array "toto" is an encoded array$arr = ["foo" => "bar", "toto" => json_encode(["forty", "two"])];echo json_encode($arr); // outputs : {"foo":"bar","toto":"[\"forty\",\"two\"]"}您可以先解码,然后再重新编码整个数组/对象$arr = ["foo" => "bar", "toto" => json_encode(["forty", "two"])];echo json_encode($arr); //{"foo":"bar","toto":"[\"forty\",\"two\"]"}$arr["toto"] = json_decode($arr["toto"]);echo json_encode($arr); //{"foo":"bar","toto":["forty","two"]}

德玛西亚99

试试这个:return response()->json($services, 200, [], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);如果数据库中有未编码的字符串数据。参考 json 标志以及如何在 Laravel 中使用标志。顺便说一句,Laravel理解何时将 Collection 作为响应返回并将其序列化,您可以使用return $services;.PS看看Cid的答案,如果您的数据已经被编码并作为字符串存储在数据库中。
打开App,查看更多内容
随时随地看视频慕课网APP