0

我将数组编码为 json 并得到

{"payment_providers":[{"name":"ccsave","revenue":[{"date":"2013-03-18","sales":"51.00","items":"2","median_item_price":"20.50"}]},{"name":"checkmo","revenue":[{"date":"2013-03-18","sales":"79.00","items":"5","median_item_price":"8.00"}]},...

但是我需要:

{
    "payment_providers":[
       {"name":"ccsave",
        "revenue":[
            {"date":"2013-03-18","sales":"51.00","items":"2","median_item_price":"20.50"}
         ]
        },
        {"name":"checkmo","revenue":[
           {"date":"2013-03-18","sales":"79.00","items":"5","median_item_price":"8.00"}
         ]
        }, ...

我怎样才能让 Json 看起来很漂亮?

4

1 回答 1

1

有一个 PHP 函数 json-encode,在这里查看文档:http: //php.net/manual/en/function.json-encode.php

并在这里检查类似的问题:Pretty-Printing JSON with PHP

于 2013-03-19T09:37:42.823 回答