我将数据存储在表中,将数组存储为一个字符串,当我获取该数据时,我不使用'“”'来获取它,第二个问题是我用了slaches来获取它!像fonctionnalites。 这就是我得到的
{
"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);
}
答案 0 :(得分: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"]}
答案 1 :(得分:1)
尝试一下:
format(newFormat, "%d-%m-%Y")
[1] "03-04-1995" "04-04-1995"
如果数据库中有未编码的字符串数据。
Reference to json flag以及flags are used in Laravel的方式。
顺便说一句,当Laravel understands返回Collection作为响应并序列化它时,您可以只使用return response()->json($services, 200, [], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
。
P。 S.如果您的数据已经被编码并作为字符串存储在数据库中,请查看Cid's answer。