数据格式
{ { "prtg-version": "17.3.33.2753", "treesize": 4, "sensors": [ { "objid": 19913, "probe": "广东联迪", "group": "关键业务感知", "device": "教育资源", "sensor": "PING 1", "status": "正常运行", "status_raw": 3 }, { "objid": 19919, "probe": "广东联迪", "group": "关键业务感知", "device": "教育资源", "sensor": "HTTPS 1", "status": "正常运行", "status_raw": 3 }, { "objid": 22236, "probe": "广东联迪", "group": "关键业务感知", "device": "校园网", "sensor": "Ping", "status": "正常运行", "status_raw": 3 }, { "objid": 22238, "probe": "广东联迪", "group": "关键业务感知", "device": "云网盘", "sensor": "Ping", "status": "正常运行", "status_raw": 3 } ] }
项目需求格式
array(3) { [0]=> string(12) "教育资源" [1]=> string(9) "校园网" [2]=> string(9) "云网盘" }
数据清洗
$data = file_get_contents("data.json"); //转为数组格式; $arr = json_decode($data, true); $dataInfo = $arr["sensors"]; //创建新的数组; $newArr = array(); //获取数组的长度; $len = count($dataInfo); //遍历数组; foreach ($dataInfo AS $k => $v) { if (stripos($dataInfo[$k]["sensor"], 'PING') !== false) { $newArr[] = $v["device"]; } } //输出数组; echo "<pre>"; var_dump($newArr);
lockdatav Done!