I am trying to parse the following json that I got through a web service in php.
$string = [{xxx:"xxx",yyy:"yyy",zzz:"zzz"}, {xxx:"xxx",yyy:"yyy",zzz:"zzz"}];
I try to parse it as with json_decode but it doesn't work.
$json = json_decode($string);
Returns nothing. What should I do?
asked Jan 6, 2012 at 0:44
1 Answer 1
That's not valid JSON. First of all, the entire thing needs to be a string. Use single-quotes here. Then, every name/value within the string needs to be double-quoted. Like so:
<?php
$string = '{ "one": {"xxx": "xxx", "yyy": "yyy", "zzz": "zzz"}, "two": {"xxx": "xxx", "yyy": "yyy", "zzz": "zzz"}}';
$json = json_decode($string);
var_dump($json);
?>
http://codepad.org/sOeEfOnr
http://php.net/manual/en/function.json-decode.php
answered Jan 6, 2012 at 0:53
lang-php
print_r($json)
?$string =
breaks it. Is it part of your response?