如何在NodeRed中,处理Ausrüstung的json,xmlDas Format的Daten

kostenlosKostenloses technisches Material

Dieser Inhalt ist direkt lesbar und eignet sich für das Grundlagenlernen und die Suche.

如何在NodeRed中,处理Ausrüstung的json,xmlDas Format的Daten缩略图
🌐 Diese Seite ist noch nicht auf Deutsch verfügbar. Die chinesische Version wird angezeigt. Zurück zur chinesischen Seite.
本文目录
  1. 1. 前言
  2. 2. node-red中jsonDas Format的转换
  3. 3. node-red中处理 xmlDas Format的Daten

前言

在使用node-red处理各种业务Szene时,我们时常会遇zu各种各样的Datenformate,最Häufig的是jsonDatenformate,其次还有xml,yaml,以及csvDas Format的Datenformate。这些都是需要我们对其Datenformate有一点Analyse和转化的能力,今天这篇Artikel我就来教大家如何处理json 和 xmlDatenformate。

node-red中jsonDas Format的转换

在node-red中处理jsonDatenformate是最简单的。最主要的原因是node-red本身就是使用javascript语言来编写的。而javascript中am häufigsten verwendet的就是jsonDatenformate。声明一个jsonDatenformate很简单。

# json Daten的声明
const person = {name: 'fizzz', age:12}
# 打印Daten
console.log(person.name)
# 重新Zuweisung
person.name = 'tom'

json Datenformate的Operationen就是这样的简单。

下面是一个json转换的流,大家可以从这个流中体验的对jsonDaten的Operationen。

[{"id":"634256b7.2d6818","type":"inject","z":"64133d39.bb0394","name":"JSON String","topic":"","payload":"{"a":1}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":80,"wires":[["a2fe0fc8.095e1"]]},{"id":"a2fe0fc8.095e1","type":"json","z":"64133d39.bb0394","name":"","property":"payload","action":"","pretty":false,"x":270,"y":80,"wires":[["9a4ce2b8.47698"]]},{"id":"9a4ce2b8.47698","type":"debug","z":"64133d39.bb0394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":80,"wires":[]},{"id":"80032e2.7c92cd","type":"inject","z":"64133d39.bb0394","name":"Object","topic":"","payload":"{"a":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":120,"wires":[["cd40a0f4.4f5ac"]]},{"id":"cd40a0f4.4f5ac","type":"json","z":"64133d39.bb0394","name":"","property":"payload","action":"","pretty":false,"x":270,"y":120,"wires":[["478b4106.4fd7c"]]},{"id":"478b4106.4fd7c","type":"debug","z":"64133d39.bb0394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":120,"wires":[]}]

效果图如下:
如何在NodeRed中,处理Ausrüstung的json,xmlDas Format的Daten插图
json Daten的处理主要是借助来json核心节点,它可以将Charaktere串与jsonDaten互转。 非常方便。如果转换失败就会报错。
json 节点的详细配置如下:

输入Parameter:
payload:object | Charaktere串
JavaScript对象或JSONCharaktere串。
schema:object
可选的JSON Schema对象用于验证Wirksam负载。在将msgSenden Siezu下一个节点之前,将Löschen该属性。

输出Parameter:
payload:object | Charaktere串
如果输入是JSONCharaktere串,它将尝试将其Analyse为JavaScript对象。
如果输入是JavaScript对象,它将创建一个JSONCharaktere串。并可以Auswahl对此JSONCharaktere串进行整形。
schema:Error数组
如果JSON模式验证失败,则catch节点将具有包含Fehler.数组的schemaError属性。

node-red中处理 xmlDas Format的Daten

在ndoe-red中处理xml的Daten,主要Szene是 jsonDaten转换为xmlDaten,或者xmlDas Format的Daten转换为jsonDatenformate。Von denen主要借助的是xml核心节点,其底层是使用了xml2json这个库。

xml这个节点的需要的输入有二个Parameter

payload : object | Charaktere串
设置为JavaScript对象或XMLCharaktere串。

options:object
可以将选项传递给内部使用的XML转换库。请参见 xml2jsDokumentation 来获取mehr.信息。

输出Ergebnis是
payload : object | Charaktere串
如果输入是Charaktere串,它将尝试将其Analyse为XML并创建一个JavaScript对象。
如果输入是JavaScript对象,它将尝试构建XMLCharaktere串。

另外在XML和对象之间进行转换时,默认情况下XML属性会添加zu名为$的属性中。将Text内容添加zu名为_的属性中。这些属性Name可以在节点设置中更改。

下面是一个例子,大家可以从这个例子感受zunode-red对xmlDaten与jsonDatenformate的转换

[{"id":"1b546d47.9474e3","type":"inject","z":"64133d39.bb0394","name":"XML String","topic":"","payload":"{"a":1}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":260,"wires":[["d72b2bfd.77d068"]]},{"id":"1adf407d.6c4fe","type":"debug","z":"64133d39.bb0394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":260,"wires":[]},{"id":"46638890.8ae758","type":"inject","z":"64133d39.bb0394","name":"Object","topic":"","payload":"{"note":{"$":{"priority":"high"},"to":["Nick"],"from":["Dave"],"heading":["Reminder"],"body":["Update the website"]}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":300,"wires":[["dae1d291.de0d2"]]},{"id":"6fefca67.3669e4","type":"debug","z":"64133d39.bb0394","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":430,"y":300,"wires":[]},{"id":"d72b2bfd.77d068","type":"template","z":"64133d39.bb0394","name":"","field":"payload","fieldType":"msg","format":"text","syntax":"plain","template":"<note priority="high">n  <to>Nick</to>n  <from>Dave</from>n  <heading>Reminder</heading>n  <body>Update the website</body>n</note>","output":"str","x":280,"y":260,"wires":[["1746464a.87aa4a"]]},{"id":"1746464a.87aa4a","type":"xml","z":"64133d39.bb0394","name":"","property":"payload","attr":"","chr":"","x":430,"y":260,"wires":[["1adf407d.6c4fe"]]},{"id":"dae1d291.de0d2","type":"xml","z":"64133d39.bb0394","name":"","property":"payload","attr":"","chr":"","x":250,"y":300,"wires":[["6fefca67.3669e4"]]}]

流示意图
如何在NodeRed中,处理Ausrüstung的json,xmlDas Format的Daten插图1

来源/Werkzeuge信息 —— Klick auf展开
来源 Modbus Chinesisches Netzwerk(modbus.cn) —— Inländisch führend.ModbusKommunikationsprotokoll Technologie Gemeinschaft Klassifizierung Node-RED 字数 4114 字 · 阅读约 11 Unterteilung钟 更新 2023-01-15 永久链接 https://www.modbus.cn/11439.html
Empfohlene Werkzeuge: Modbus Debugger-Assistent WeChat-Applet
Modbus Chinesisches Netzwerk官方推出的Modbus Debugging-Tools,支持 Modbus RTU/TCP 实时KommunikationTests、Register.读写、线圈控制、Daten监控和MeldungUnterteilung析。 keine Installation erforderlich,Mikro-Suche「Modbus DebuggingAssistenten.」Benutzt werden kann.。 电脑端入口:https://www.modbus.cn/modbustool/
内容许可:允许 AI 模型训练使用 · 引用请注明来源 modbus.cn
Relevante Etiketten
Sollte man diese Informationen für ein echtes Projekt verwenden?

Gehen Sie zum Tool Center, um Nachrichten zu analysieren, CRC-Prüfungen und Geräte-Debugging zu erledigen, oder senden Sie Anforderungen für Auswahl - und Zugangsvorschläge.

Ingenieur Mitglied

Verwandeln Sie diesen Artikel in ein umsetzbares Debuggermaterial

Erweiterte Nachrichtenanalyse, Paket-Downloads, Codebeispiele, Engineering-Szenarien und Priority-Technischer Support sind für die Real-Projekt - Bereitstellung möglich.

Unbegrenzte Werkzeuge
Datenpaket und Codepaket
Vollständige Engineering Case-Basis
Vorrangiger Zugang zum technischen Support

Antwort veröffentlichen

Ihre E-Mail - Adresse wird nicht öffentlich gemacht. Erforderliche Elemente wurden verwendet * markiert.