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

2
  • 5
    You need to wrap your input in [ and ] to make it a valid array in JSON notation. Commented Nov 9, 2012 at 1:45
  • you can use jsonlint.com to validate your json string. It's usefull sometime. Commented Nov 9, 2012 at 1:48

1 Answer 1

4

Wrap your list into javascript array:

$json = '{"foo": "12345"}, {"foo": "6789"}, {"bar": "001100"}';
$json = '[' . $json . ']';
$obj = json_decode($json);
print $obj[0]->{'foo'};
Sign up to request clarification or add additional context in comments.

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.