请帮我将此 Perl 数组转换为 PHP 数组:
{
'method' => 'sip_endpoint.save',
'parameters' => {
'transport' => [
'UDP' <-------especially this one
],
'object_type' => 'sip_endpoint',
'nat' => 'yes'
}
}
通过简单的替换 .. 这可以转换为有效json
$json = "{
'method' => 'sip_endpoint.save',
'parameters' => {
'transport' => [
'UDP'
],
'object_type' => 'sip_endpoint',
'nat' => 'yes'
}
}";
$json = str_replace(array("'","=>"), array('"',":"), $json);
$array = json_decode($json,true);
print($array['parameters']['transport'][0]); //what you want
输出
UDP