Php反序列化字符串

时间:2013-03-26 22:41:57

标签: php arrays serialization

当我var_dump($string);时,我得到了

string(894) "[{"id":"11","value":"Gotowy do u\u017cytku"},{"id":"12","value":"Na 4 k\u00f3\u0142kach"},{"id":"13","value":"20 minut - rozgrzany do pracy"},{"id":"14","value":"Pow. u\u017cytkowa 108 cm2"},{"id":"15","value":"Piec i grill w jednym"},{"id":"16","value":["tekst","\/images\/alfa\/domowa\/forninox\/1.jpg","lightbox"]},{"id":"17","value":["tekst","\/images\/alfa\/domowa\/forninox\/1.jpg","lightbox"]},{"id":"18","value":["tekst","\/images\/alfa\/domowa\/forninox\/3.jpg","lightbox"]},{"id":"19","value":["tekst","\/images\/alfa\/domowa\/forninox\/2.jpg","lightbox"]},{"id":"20","value":"cm 127"},{"id":"21","value":"cm 189"},{"id":"22","value":"cm2 108"},{"id":"23","value":"Kg 340"},{"id":"24","value":"\u00a6 cm 25\/20"},{"id":"25","value":"Mat. ceramiczny"},{"id":"26","value":"Stal nierdzewna"},{"id":"27","value":"W\u0142. ceramiczne"},{"id":"28","value":"min 20"},{"id":"29","value":"7"}]" 

我把这个字符串放到数组中,所以我做反序列化,就像这样:

$a = unserialize($string); 
var_dump($a);

但是在输出中我得到了:

bool(false) 

Enybody知道我做错了什么?

2 个答案:

答案 0 :(得分:3)

你有一个json字符串。你想用

$arr = json_decode($string, TRUE);

将其反序列化为关联数组。

答案 1 :(得分:0)

它没有序列化,但json编码。使用:

$decoded = json_decode($string);