我有以下 php 数组,并希望将其打印为干净的 JSON 文件,但括号和逗号周围有额外的引号。虽然我得到的当前 JSON 是有效的 JSON,但它不是我想要的格式。请参阅下面的 PHP 数组、我的 json_encode 输出和首选 json 输出:
Array
(
[0] => {
[1] => code : "EU27",
[2] => debtA : 967576248244,
[3] => debtB : 6971817122583,
[4] => id : "eur",
[5] => name : "EU",
[6] => popY : 8584663069945,
[7] => popZ : 7565913300548 }
[8] => ,
[9] => {
[10] => code : "US",
[11] => debtA : 9090198981283,
[12] => debtB : 92189801202,
[13] => id : "usa",
[14] => name : "United States",
[15] => popY : 4514703786570,
[16] => popZ : 774697283542 }
)
当前 json_encode 输出:
[
" {",
" code : \"EU27\",",
" debtA : 1739414366187,",
" debtB : 8719158563660,",
" id : \"eur\",",
" name : \"EU\",",
" popY : 460572909944,",
" popZ : 2396933253407 }",
" ,",
" {",
" code : \"US\",",
" debtA : 7810766144794,",
" debtB : 10536751929567,",
" id : \"usa\",",
" name : \"United States\",",
" popY : 8571487476842,",
" popZ : 1716024078740 }"
]
首选 JSON 输出:
[
{
code : "EU27",
debtA : 1739414366187,
debtB : 8719158563660,
id : "eur",
name : "EU",
popY : 460572909944,
popZ : 2396933253407 },
{
code : "US",
debtA : 7810766144794,
debtB : 10536751929567,
id : "usa",
name : "United States",
popY : 8571487476842,
popZ : 1716024078740 }
]
我一直在搜索 stackoverflow 并发现了类似的问题,但无法使其正常工作。可能是因为我对php和php数组的理解。任何帮助表示赞赏。