夏侯哥哥 2019-07-21 17:30 采纳率: 0%
浏览 333

新手求教:如何用lua解析json电报

GET http://192.168.1.122:8080/devices/019D202A/telegrams 得到的电报

{
  "header" : {
    "httpStatus" : 200,
    "content" : "telegrams",
    "gateway" : "DC-GW/EO-IP v0.99.6",
    "timestamp" : "1970-01-01T08:07:46.898+0800"
  },
  "telegrams" : [ {
    "deviceId" : "019D202A",
    "friendlyId" : "hhh666",
    "physicalDevice" : "99999",
    "timestamp" : "1970-01-01T08:05:14.072+0800",
    "direction" : "from",
    "functions" : [ {
      "key" : "supplyVoltage",
      "value" : 3.60,
      "unit" : "V"
    },{
    "deviceId" : "019D202A",
    "friendlyId" : "hhh666",
    "physicalDevice" : "99999",
    "timestamp" : "1970-01-01T08:06:24.098+0800",
    "direction" : "from",
    "functions" : [ {
      "key" : "supplyVoltage",
      "value" : 3.66,
      "unit" : "V"
    }, {
      "key" : "illumination",
      "value" : 244.00,
      "unit" : "lx"
    }, {
      "key" : "temperature",
      "value" : 21.20,
      "unit" : "°C"
    }, {
      "key" : "motionDetected",
      "value" : "true",
      "meaning" : "PIR on"
    }, {
      "key" : "occupancyButton",
      "value" : "pressed",
      "meaning" : "Button pressed"
    } ],
    "telegramInfo" : {
      "data" : "B77A6A08",
      "status" : "0",
      "dbm" : -61,
      "rorg" : "A5"
    }
  } ]
}

如何用lua脚本解析一个值输出;如上面代码中有“supplyVoltage”“illumination”“temperature”“motionDetected”“occupancyButton”等值,只取一个值
解析格式类似与

function parameter (value) 
return "/temperature/setTemp.php?temp="..value end 

这种格式

啊啊~~~~~!

  • 写回答

1条回答 默认 最新

  • Voidmatrix 2021-03-21 00:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键