node-red - 类型错误 : Cannot assign to read only property '_msgid'

标签 node-red

我正在尝试 node-red...

enter image description here

我做这个网络查询 https://api.forecast.io/forecast/

这是给定的输出:

{"latitude":-25.74486,"longitude":28.18783,"timezone":"Africa/Johannesburg","offset":2,"currently":
{"time":1462871342,"summary":"Foggy","icon":"fog","precipIntensity":0,"precipProbability":0,
"temperature":18.08,"apparentTemperature":18.08,
"dewPoint":9.3,"humidity":0.57,"windSpeed":3.75,"windBearing":351,"visibility":2.78,
"cloudCover":0.23,"pressure":1024.87,"ozone":252.43}}

这似乎是正确的。

Parse Weather中的代码是

  //parse forecast.io message

 var weather = JSON.parse(msg.payload);

 return weather.currently.temperature;

我得到的错误是:

TypeError: Cannot assign to read only property '_msgid' of 19.49

这个值似乎还可以。

我做错了什么?

提前致谢。

最佳答案

问题出在您的 Parse Weather 函数中。您正在返回一个 int (18.08),Function 节点需要返回一个 msg 对象。

尝试这样的事情:

var weather = JSON.parse(msg.payload);
msg.payload = weather.currently.temperature;

return msg;

关于node-red - 类型错误 : Cannot assign to read only property '_msgid' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37135372/

相关文章:

Node-red 如何读取模板节点中的全局变量

javascript - 如何在模板节点中找到完整的数组

node.js - node-red - API 响应缓存

error-handling - 来自节点的Node-RED Handle错误,没有抛出标准异常

javascript - 在 Node red 中设置全局变量

node.js - 如何在 Node-RED exec node 命令中转义空格

node.js - Node 红色: share data between node

node-red - 如何将对象添加到 Node-RED msg.payload

python - POST 图像并以 Node-red 在仪表板中显示