php 解析文件不知道什么格式

发布于 2024-09-10 16:04:59 字数 1668 浏览 4 评论 0原文

我有一个可以返回温度数据等的硬件。但我不确定这是什么格式。我想用 php 解析它,任何有关解析数据的最佳或最简单方法的建议。我将把数据存储在 mysql 数据库中,并且该数据将每 30 秒插入一个。

以下是数据:

{name:"Enviro",date:"07/22/10 17:32:34",uptime:"0d 19:06:28",scale:0,macaddr:"00: XX:XX:XX:XX:XX",devtype:"24",刷新:"30",传感器:[{label:"机架温度",tempf:"70.88",tempc:"21.60",highf:"72.50 ",highc:"22.50",lowf:"69.98",lowc:"21.10",警报:1,类型:38,启用:1,湿度:"37.27",highh:"45.72",lowh:"34.01", heati:"76.79",heatic:"24.88",highhi:"77.07",highhic:"25.03",lowhi:"76.57",lowhic:"24.76",hienabled:0},{label:"外部传感器 1" ,tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",警报:0,类型:0,启用:0}, {标签:“暖通空调”,tempf:“46.27”,tempc:“7.93”,highf:“67.87”,highc:“19.93”,lowf:“43.70”,lowc:“6.50”,警报:1,类型:16 ,enabled:1},{label:"外部传感器 3",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00 ",alarm:0,type:0,enabled:0},{label:"外部传感器 4",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf :"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"外部传感器 5",tempf:"32.00",tempc:"0.00",highf:"32.00 ",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"分机。传感器 6",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",警报:0,类型:0,启用: 0}],switch_sen:[{label:"气流",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label: " ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用: 1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1 ,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0},{标签:" ",启用:1,警报:1,状态:0}]}

I have an piece of hardware that returns temperature data etc. I am not sure what format this is though. I would like to parse it with php any suggestions on the best or easiest way to parse the data. I will be storing the data in a mysql database and this data will be inserted one every 30 seconds.

Below is the data:

{name:"Enviro",date:"07/22/10 17:32:34",uptime:"0d 19:06:28",scale:0,macaddr:"00:XX:XX:XX:XX:XX",devtype:"24",refresh:"30",sensor:[{label:"Rack Temp",tempf:"70.88",tempc:"21.60",highf:"72.50",highc:"22.50",lowf:"69.98",lowc:"21.10",alarm:1,type:38,enabled:1,humid:"37.27",highh:"45.72",lowh:"34.01",heati:"76.79",heatic:"24.88",highhi:"77.07",highhic:"25.03",lowhi:"76.57",lowhic:"24.76",hienabled:0},{label:"Ext. Sensor 1",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"HVAC",tempf:"46.27",tempc:"7.93",highf:"67.87",highc:"19.93",lowf:"43.70",lowc:"6.50",alarm:1,type:16,enabled:1},{label:"Ext. Sensor 3",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"Ext. Sensor 4",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"Ext. Sensor 5",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0},{label:"Ext. Sensor 6",tempf:"32.00",tempc:"0.00",highf:"32.00",highc:"0.00",lowf:"32.00",lowc:"0.00",alarm:0,type:0,enabled:0}],switch_sen:[{label:"Air Flow",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0},{label:" ",enabled:1,alarm:1,status:0}]}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笔落惊风雨 2024-09-17 16:04:59

只需将其放入数组中即可:

$str = '...';
$arr = json_decode(preg_replace('/([{,])([^:{,]+):/', '${1}"${2}":', $str));
var_dump($arr);

简单/完美/最佳;-)

Simply get it in an array:

$str = '...';
$arr = json_decode(preg_replace('/([{,])([^:{,]+):/', '${1}"${2}":', $str));
var_dump($arr);

Simple/Perfect/Best ;-)

娇纵 2024-09-17 16:04:59

它认为它是 JSON 格式。

It think it is in JSON format.

森末i 2024-09-17 16:04:59

您可以使用 PEAR 包 - Services_JSON 解析它

You can parse it using PEAR package - Services_JSON

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文