直接这样就行啦~ 谢谢大家的帮忙啦~~ $xml = simplexml_load_string("<InstallPolicyConfig PolicyId=\"PolicyId\" Value=\"Value\" Type=\"Type\" IsAllow=\"IsAllow\"/>");echo json_encode(array_shift(get_object_vars($xml)));只不过这样会出现下面的提示:Debug Strict (PHP 5): /PHP/tests/test.php line 51 - Only variables should be passed by reference(什么只能通过引用传递变量什么的…… 不是太明白~)
$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
{
echo $key, '=>', $val;
}
<InstallPolicyConfig PolicyId="PolicyId" Value="Value" Type="Type" IsAllow="IsAllow"/>
这个 组成的一个文件。 我要把每条中的属性取出来,然后取它的json编码的格式是这样的:
{"PolicyId":"8df3ecf1-9b05-4ae3-86a4-0c9f26487c9","Value":"C0A86F6F","Type":"IP","IsAllow":false}
$xml = simplexml_load_string("<InstallPolicyConfig PolicyId=\"PolicyId\" Value=\"Value\" Type=\"Type\" IsAllow=\"IsAllow\"/>");echo json_encode(array_shift(get_object_vars($xml)));只不过这样会出现下面的提示:Debug Strict (PHP 5): /PHP/tests/test.php line 51 - Only variables should be passed by reference(什么只能通过引用传递变量什么的…… 不是太明白~)