0

I want this string {"id": "23", "flag":"1", "qty": "2", "size": "23"},{"id":"12", "flag":"2", "qty":"1", "size":"12"} to json array.

I have used following code but not working.

$data = '{"id": "23", "flag":"1", "qty": "2", "size": "23"},{"id":"12", "flag":"2", "qty":"1", "size":"12"';


echo json_decode($data, true);

If anyone know please help me how to do this.

1
  • 2
    You can't decode or encode it to a json array, because your data is not a json array. It's two separate json objects. Put [] around it and it will work: 3v4l.org/KX6tm Commented Jul 9, 2018 at 11:21

2 Answers 2

1
$data = '[{"id": "23", "flag":"1", "qty": "2", "size": "23"},{"id":"12", "flag":"2", "qty":"1", "size":"12"}]';

echo '<pre>' . print_r(json_decode($data),true) . '</pre>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You! for your time
1

Your JSON is not valid you should change it to this because it is a JSON array

[{"id": "23", "flag":"1", "qty": "2", "size": "23"},{"id":"12", "flag":"2", "qty":"1", "size":"12"}]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.