我有以下php數組,並希望將其作爲乾淨的JSON文件進行打印,但我在括號和逗號周圍收到額外的引號。雖然我得到的當前JSON是有效的JSON,但它不是我想如何格式化的。見下文PHP數組,我json_encode輸出和首選JSON輸出:PHP數組json_encode添加額外引號
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 }
]
我一直在尋找計算器,發現類似的問題,但不能得到它的工作。可能是因爲我對php和php數組的理解。任何幫助表示讚賞。
爲什麼你想要不帶引號的屬性?那是無效的json – sroes 2013-03-14 08:21:36
您是否創建了該數組?您應該爲此使用2維數組。 – Antony 2013-03-14 08:27:19
只是爆破你的數組值。 – revoua 2013-03-14 08:28:11