Raju  Dudhrejiya Raju Dudhrejiya - 5 months ago 9
JSON Question

How to convert json data to array in php?

I have json string live below, I try to convert array but I am not success can anyone please help me, thank you advance.

Example 1 : s:59:"[{"item_id":"UTILITY CON CERNIERA","qty":1,"points":"110"}]";

Example 1 : s:109:"[{"item_id":"UTILITY CON CERNIERA","qty":1,"points":"110"},{"item_id":"PESA VALIGIA","qty":1,"points":"120"}]";

Answer

Your data is serialized as well as json encoded. So you have to use:-

json_decodealong with unserialize like below:-

<?php

$data = 's:59:"[{"item_id":"UTILITY CON CERNIERA","qty":1,"points":"110"}]"';
print_r(json_decode(unserialize($data),true));
?>

And

<?php

$data = 's:109:"[{"item_id":"UTILITY CON CERNIERA","qty":1,"points":"110"},{"item_id":"PESA VALIGIA","qty":1,"points":"120"}]"';
print_r(json_decode(unserialize($data),true));
?>

https://eval.in/590757 And https://eval.in/590758

For more reference:-

http://php.net/manual/en/function.json-decode.php

http://php.net/manual/en/function.unserialize.php