Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用php7.1的magento2中,Json以[开头,使用Json_encode时以“.”开头_Php_Arrays_Json_Php 7.1_Magento 2.3 - Fatal编程技术网

在使用php7.1的magento2中,Json以[开头,使用Json_encode时以“.”开头

在使用php7.1的magento2中,Json以[开头,使用Json_encode时以“.”开头,php,arrays,json,php-7.1,magento-2.3,Php,Arrays,Json,Php 7.1,Magento 2.3,我希望我的json以{开头,但如果使用json_编码,它将被转换为字符串,我将在ubuntu上使用php7.1,并在magento 2.3上工作 这是我用下面的代码得到的,我不想要'[' [ { "success": "true", "data": { "mainimages": [ { 这是我的密码 $response = array( array( "success" =

我希望我的json以{开头,但如果使用json_编码,它将被转换为字符串,我将在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\u encode($response[0])
?或者干脆去掉外部的
数组()
?你需要养成帮助你解决问题的习惯。你会获得积分,其他人也会被鼓励帮助你。@Jay Blanchard我仍然面临问题,所以一旦问题解决,我会接受答案。嗨@RiggsFolly谢谢你的回复。事情是$sliderimage也在数组中,所以现在我得到了一些“styletagline”:“#看起来向右滑动”,“newarrivalindex”:3,“instagramindex”:9,“editorwishlistviewall”:““sliderimage”:“}[]除非我错过了什么,那应该不会有太大的区别,否则我将答案更改为将
$sliderimage=['xz.jpg','ab.png'];
更改为数组我正在获取[]在我的json结尾。我的代码没有,所以很明显你在做我没有做的事情。你的代码
返回
$response
,因此在其他地方将其转换为json。返回后你如何处理此响应?这可能就是你的问题所在