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.

Samir Sheikh
  • 2,283
  • 2
  • 19
  • 37
  • 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: https://3v4l.org/KX6tm – Loek Jul 09 '18 at 11:21

2 Answers2

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"}]

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>';
Gabor
  • 566
  • 5
  • 14