如何在没有引号的情况下获得我的数组结果
How I can get my array result without quotes
我在 table 中获取我的数据 我有一个存储为字符串的数组 当我获取此数据时我没有使用 '""' 获取它,第二个问题我得到了带着懒汉!像functionnalites。
这就是我得到的
{
"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);
}
试试这个:
return response()->json($services, 200, [], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
如果数据库中有 non-encoded 个字符串数据。
Reference to json flag and how flags are used in Laravel.
顺便说一下,Laravel understands 当 Collection 作为响应返回并序列化时,您可以直接使用 return $services;
.
P. S. 如果您的数据已经编码并作为字符串存储在数据库中,请查看 。
您的成员 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\"]"}
你可以先解码,然后re-encoding整个array/object
$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"]}
我在 table 中获取我的数据 我有一个存储为字符串的数组 当我获取此数据时我没有使用 '""' 获取它,第二个问题我得到了带着懒汉!像functionnalites。 这就是我得到的
{
"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);
}
试试这个:
return response()->json($services, 200, [], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
如果数据库中有 non-encoded 个字符串数据。
Reference to json flag and how flags are used in Laravel.
顺便说一下,Laravel understands 当 Collection 作为响应返回并序列化时,您可以直接使用 return $services;
.
P. S. 如果您的数据已经编码并作为字符串存储在数据库中,请查看
您的成员 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\"]"}
你可以先解码,然后re-encoding整个array/object
$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"]}