Php 如何将数组转换为json解码格式

Php 如何将数组转换为json解码格式,php,json,laravel,Php,Json,Laravel,我想把我的数组转换成JSON格式,我该怎么做呢。 下面是我的代码 $arr['more_images'][] = $datas; echo '<pre>'; print_r($arr['more_images']); echo '</pre>'; In above code i am getting output like this <pre>Array ( [0] => Array (

我想把我的数组转换成JSON格式,我该怎么做呢。 下面是我的代码

    $arr['more_images'][] = $datas;
    echo '<pre>';
    print_r($arr['more_images']);
    echo '</pre>';
In above code i am getting output like this
<pre>Array
(
    [0] => Array
        (
            [0] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_3749.jpg
            [1] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_4923.jpg
            [2] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_9362.jpg
        )

)
</pre>
But I want output like this

        [
          {
               http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_3749.jpg
    }
          {    http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_4923.jpg
    }
          {    http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_9362.jpg
            }
    ]
$arr['more_images'][]=$datas;
回声';
打印($arr['more_images']);
回声';
在上面的代码中,我得到如下输出
$arr['more_images'][] = $datas;
        echo '<pre>';
        print_r(json_encode($arr['more_images']));
        echo '</pre>';
排列 ( [0]=>阵列 ( [0] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_3749.jpg [1] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_4923.jpg [2] => http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_9362.jpg ) ) 但我想要这样的输出
$arr['more_images'][] = $datas;
        echo '<pre>';
        print_r(json_encode($arr['more_images']));
        echo '</pre>';
[ { http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_3749.jpg } { http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_4923.jpg } { http://sale4allz.com/sale4allz/public/uploads/product_more_images/178_9362.jpg } ]
我该怎么做?如果有人知道解决方案,请告诉您应该尝试以下方法:

header('Content-Type: application/json');
echo json_encode( $arr['more_images']);
$arr['more_images'][]=json_encode($datas);
回声';
打印($arr['more_images']);
回声';

$arr['more_images'][]=$datas;
回声';
打印(json编码($arr['more_images']);
回声';

您应该使用以下逻辑:


使用echo json_encode($arr['more_images'])您不会在索引元素上得到这些花括号。如果你
JSON\u FORCE\u OBJECT
那么所有的东西都会被转换成对象,你会失去方括号。你的问题不清楚。请解释为什么您希望更改结构--好处是什么?客户要求我希望每个元素都是{}单独的。不需要方括号,我得到的输出像[[”“,”“,”“]]