0

请帮我将此 Perl 数组转换为 PHP 数组:

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

1 回答 1

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
于 2013-03-19T23:38:15.860 回答