可能重复:
如何解码这个 JSON 字符串?
从另一个站点获取数据时,我得到了这个
{"user_id":"908508","item_id":"341","quantity":"3","status":"0"}
有时字段多,有时字段少
我怎样才能把它变成一个数组
"name" => "X"
可能重复:
如何解码这个 JSON 字符串?
从另一个站点获取数据时,我得到了这个
{"user_id":"908508","item_id":"341","quantity":"3","status":"0"}
有时字段多,有时字段少
我怎样才能把它变成一个数组
"name" => "X"
使用 json_decode
json_decode($jsonstring);
尝试这个:
$url = "http://...";
$json = file_get_contents($url);
$array = json_decode($json, TRUE /** forces to decode into PHP array */);
print_r($array);
<?php
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345
?>