1

我有一个这样的输入字符串:

{"id":1,"name":"John","age":50,"surname":"Smith","category":"something","money":500}

我需要得到一个像这样的数组:

大批

(

 [id] => 1

 [name] => John

 [age] => 50 

 [...]

)

或另一种将该记录插入mysql数据库的方法......

但我对正则表达式不是很熟悉......我该怎么做?

4

1 回答 1

4

那是json 格式,您不需要拆分任何可用于json_decode将其解码为数组的内容

$str = '{"id":1,"name":"John","age":50,"surname":"Smith","category":"something","money":500}';
$str = json_decode($str,true);

echo "<pre>";
print_r($str);

输出

Array
(
    [id] => 1
    [name] => John
    [age] => 50
    [surname] => Smith
    [category] => something
    [money] => 500
)
于 2012-10-13T23:29:58.050 回答