我尝试从 json 文件中获取两条信息:“Principal”和 WiFiMAC。我需要它来导出名称和 MAC 以导出到数据库中。
{
"messages":
{"message":"150 devices(s) returned."},
"devices":
{"device":
[
{"@id":"121","uuid":"xxx-xxx-xxxxxxxxx-xxx-x-xxxxx","principal":"John Rambo","blockReason":0,"clientId":"anything","compliance":0,"countryCode":49,"countryId":68,"countryName":"Germany","details":
[
{"entry":[
{"key":"Model","value":"anything"},
{"key":"AvailableDeviceCapacity","value":57.360877990722656},
{"key":"WiFiMAC","value":"123456789012"}]}]}]}}
和更多的键。
我可以像这样提取主体:
$json = file_get_contents("test.xml");
$json = json_decode($json);
echo $json->messages->message;
echo $json->devices->device[1]->principal;
但我没有机会提取 WiFiMAC。对于json中的任何设备,我都需要这个,我想我可以用foreach加载每个设备......但第一个是提取WiFiMAC。