更新时间:2023-02-04 08:44:07
我知道了. json_encode处理对象的方式与处理字符串的方式不同.我将该对象转换为字符串,并且现在可以正常使用.
I figured it out. json_encode handles objects differently than strings. I cast the object to a string and it works now.
foreach($xml->children() as $state)
{
$states[]= array('state' => (string)$state->name);
}
echo json_encode($states);