Willy Laurents Willy Laurents - 1 month ago 12
JSON Question

Why serialize return stdClass? (PHP)

i have one json but when i using serialize() return stdclass?

$json= [{"lt":"1","lot":["0","1","0"]},{"lt":"2","lot":["0","0","0"]}]


and this after serialize():

a:2:{i:0;O:8:"stdClass":2:{s:2:"lt";s:1:"1";s:3:"lot";a:3:{i:0;s:1:"0";i:1;s:1:"1";i:2;s:1:"0";}}i:1;O:8:"stdClass":2:{s:2:"lt";s:1:"2";s:3:"lot";a:3:{i:0;s:1:"0";i:1;s:1:"0";i:2;s:1:"0";}}}


i need like this but i cant solve it:

a:2:{i:0;a:2:{s:2:"lt";s:1:"1";s:3:"lot";a:3:{i:0;s:1:"0";i:1;s:1:"1";i:2;s:1:"0";}}i:1;a:2:{s:2:"lt";s:1:"2";s:3:"lot";a:3:{i:0;s:1:"0";i:1;s:1:"0";i:2;s:1:"0";}}}

Answer

Just try

serialize(json_decode($json, true));
Comments