2012-11-14 83 views
0

我想將一些JSON轉換爲PHP中的關聯數組。由於某種原因,json_decode()的結果始終爲NULL。json_decode不斷返回null

我想我的JSON必須是畸形的,但我不知道爲什麼。什麼是畸形的呢?

<?php 

$json = '{ markers:{ marker:[ { lat:50.30644, lng:18.03125, title:"Some name with accented characters ÅÄÖ", zoom:13, center:"false", street:"Dalahästvägen 56", zip:{ }, city:"117 58 MALMÖ", country:"SE", phone:"070-880 60 14", www:"domain.se/" }, { lat:59.5306, lng:18.08521, title:"ACME INC", zoom:13, center:"false", street:"ELFSBORGSVÄGEN 9", zip:{ }, city:"186 41 SIGTUNA", country:"SE", phone:"08-511 700 70", www:"acmegiantslingshots.se" }]}}' ; 

$arr = json_decode($json, true); 
print_r($arr); 

是因爲某些對象屬性沒有價值嗎?

+0

你的json無效請點擊這裏http://jsonlint.com/ – GBD

回答

4

必須使用"(雙引號)引用所有字符串和鍵以符合JSON規範。

http://jsonlint.com通常是一個很好的工具,當你有東西打破了你的JSON解析器。

+0

+1更具體的答案在同一時間:) –