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?

1
  • your json is not valid check here jsonlint.com
    – GBD
    Nov 14, 2012 at 14:47

1 Answer 1

4

All strings and keys must be quoted using " (double quotes) to comply with the JSON spec.

http://jsonlint.com is usually a good tool when you have something that breaks your JSON parser.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.