Json 以 [ 开头,当使用 json_encode 时,它以 " 在 magento2 中使用 php7.1 开头
Json starting with [ and when using json_encode it starts with " in magento2 using php7.1
我希望我的 json 以 { 开头,但是如果使用 json_encode 它会被转换成字符串,我在 ubuntu 上使用 php7.1 并且正在工作在 magento 2.3
这就是我用下面的代码得到的,我不想要'['
[
{
"success": "true",
"data": {
"mainimages": [
{
这是我的代码
$response = array(
array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
)
);
return $response;
这就是我想要的
{
"success": "true",
"data": {
"mainimages": [
{
所以像这样删除不必要的外部数组
$alldata = [1,2,3,4];
$sliderimage = ['xz.jpg','ab.png'];
$response = array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
);
echo json_encode($response);
结果
{
"success": "true",
"data": [
1,
2,
3,
4
],
"newarrivalheading": "NEW ARRIVALS",
"instagramheading": "CELEBS IN LULU",
"specialpriceheading": "SPECIAL PRICES",
"editorwishlistheading": "EDITOR'S WISHLIST",
"stylehighlightheading": "STYLE HIGHLIGHTS",
"styletagline": "#Looks to swipe right",
"newarrivalindex": 3,
"instagramindex": 9,
"editorwishlistviewall": "",
"sliderimage": [
"xz.jpg",
"ab.png"
]
}
我希望我的 json 以 { 开头,但是如果使用 json_encode 它会被转换成字符串,我在 ubuntu 上使用 php7.1 并且正在工作在 magento 2.3
这就是我用下面的代码得到的,我不想要'['
[
{
"success": "true",
"data": {
"mainimages": [
{
这是我的代码
$response = array(
array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
)
);
return $response;
这就是我想要的
{
"success": "true",
"data": {
"mainimages": [
{
所以像这样删除不必要的外部数组
$alldata = [1,2,3,4];
$sliderimage = ['xz.jpg','ab.png'];
$response = array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
);
echo json_encode($response);
结果
{
"success": "true",
"data": [
1,
2,
3,
4
],
"newarrivalheading": "NEW ARRIVALS",
"instagramheading": "CELEBS IN LULU",
"specialpriceheading": "SPECIAL PRICES",
"editorwishlistheading": "EDITOR'S WISHLIST",
"stylehighlightheading": "STYLE HIGHLIGHTS",
"styletagline": "#Looks to swipe right",
"newarrivalindex": 3,
"instagramindex": 9,
"editorwishlistviewall": "",
"sliderimage": [
"xz.jpg",
"ab.png"
]
}