如何将Perl数组转换为PHP数组?

时间:2013-03-19 22:42:13

标签: php perl

请帮我把这个Perl数组转换成PHP数组:

{
'method' => 'sip_endpoint.save',
'parameters' => {
     'transport' => [
                     'UDP'     <-------especially this one
                    ],
      'object_type' => 'sip_endpoint',
      'nat' => 'yes'
   }
}

1 个答案:

答案 0 :(得分:1)

使用简单的替换..这可以转换为有效的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