将php字符串从"JSONish"格式转换为数组php

Ary*_*mon -4 php arrays

除了爆炸之外还有什么办法可以将看起来像的字符串转换"[2,0,[]]"成数组吗?

我的数组输出应该是:

array(2,0,array())
Run Code Online (Sandbox Code Playgroud)

"[2,0,[1,2,3,4]]" 这蜇应该是:

array(2,0,array(1,2,3,4))
Run Code Online (Sandbox Code Playgroud)

我不想使用 explode, 因为它看起来像是一个非常简单的任务的代码.在JavaScript中它是一个班轮:

JSON.parse('[2,0,[1,2,3,4]]');
Run Code Online (Sandbox Code Playgroud)

Tᴀʀ*_*ᴏᴏᴅ 8

您的输入看起来像一个JSON字符串,可以使用json_decode()函数进行转换:

json_decode("[2,0,[]]", true); 

/*
Array (
    0 => 2,
    1 => 0,
    2 => 
    Array (
    ),
)
*/
Run Code Online (Sandbox Code Playgroud)