0

I'm trying to convert some JSON to an associate array in PHP. For some reason, the result of json_decode() is always NULL.

I guess my JSON must be malformed, but I don't know why. What's malformed about it?

<?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);

Is it because some of the object properties have no value?

4

1 回答 1

4

所有字符串和键必须使用"(双引号)引用以符合 JSON 规范。

当您遇到破坏 JSON 解析器的东西时, http://jsonlint.com通常是一个很好的工具。

于 2012-11-14T14:47:05.903 回答