1

Possible Duplicate:
can a JSON start with [?

This is an abbreviated version of my problem.
My json output has comma separated groups, how can i make this work?

$json = '{"foo": "12345"}, {"foo": "6789"}, {"bar": "001100"}';
$obj = json_decode($json);
print $obj[0]->{'foo'};

currently it gives me an error Notice: Trying to get property of non-object

Community
  • 1
  • 1
t q
  • 4,593
  • 8
  • 56
  • 91

1 Answers1

4

Wrap your list into javascript array:

$json = '{"foo": "12345"}, {"foo": "6789"}, {"bar": "001100"}';
$json = '[' . $json . ']';
$obj = json_decode($json);
print $obj[0]->{'foo'};
Alexei Tenitski
  • 9,030
  • 6
  • 41
  • 50