php中字符串转换为数组的内置函数

php中字符串转换为数组的内置函数,php,arrays,string,Php,Arrays,String,我正在使用来自其他站点的web api,它返回的值与字符串格式类似- [[["I eat rice","I ate rice","I am eating rice"] .... ]] 我正在考虑将其转换为数组或对象(json)。。。是否有任何方法可以使用php bulitin函数进行转换…为什么不使用json\u decode函数呢 $string = '[[["I eat rice","I ate rice","I am eating rice"]]]'; $array = json_dec

我正在使用来自其他站点的web api,它返回的值与字符串格式类似-

[[["I eat rice","I ate rice","I am eating rice"] .... ]]

我正在考虑将其转换为数组或对象(json)。。。是否有任何方法可以使用php bulitin函数进行转换…

为什么不使用
json\u decode
函数呢

$string = '[[["I eat rice","I ate rice","I am eating rice"]]]';
$array = json_decode($string);
var_dump($array);
这将是一个多维数组:

array(1) {
  [0]=>
  array(1) {
    [0]=>
    array(3) {
      [0]=>
      string(10) "I eat rice"
      [1]=>
      string(10) "I ate rice"
      [2]=>
      string(16) "I am eating rice"
    }
  }
}

为什么不使用
json\u decode
函数呢

$string = '[[["I eat rice","I ate rice","I am eating rice"]]]';
$array = json_decode($string);
var_dump($array);
这将是一个多维数组:

array(1) {
  [0]=>
  array(1) {
    [0]=>
    array(3) {
      [0]=>
      string(10) "I eat rice"
      [1]=>
      string(10) "I ate rice"
      [2]=>
      string(16) "I am eating rice"
    }
  }
}

JSON不是对象,而是文本。从API获得的字符串是JSON。阅读[
json\u decode()
]php.net/manual/en/function.json decode.php)。json不是对象,而是文本。从API获得的字符串是JSON。阅读[
json\u decode()
]php.net/manual/en/function.json decode.php)。