反序列化非标准字符串

时间:2015-12-07 17:40:16

标签: php deserialization

我有一个看起来像数组的字符串: -

'[["hello","world"],["etc","etc..."]]'

有没有办法'反序列化',即使它不是真正适当的序列化格式。

2 个答案:

答案 0 :(得分:5)

您可以将其作为数组返回,因为它是JSON:

$json = '[["hello","world"],["etc","etc..."]]';
$decoded = json_decode($json, true); // true option returns associative array
print_r($decoded);

返回:

Array
(
    [0] => Array
        (
            [0] => hello
            [1] => world
        )

    [1] => Array
        (
            [0] => etc
            [1] => etc...
        )

)

答案 1 :(得分:0)

您可以在此字符串上使用json_decode函数。