当前正在Node-RED上创建一个运行在Node.js上的ETL流,它运行在CloudFoundry上运行的Bluemix上。如何将包含在一条消息中的JSON数组转换为多个JSON对象消息?
我在查询一个Cloudant数据库,并获取包含所有文档作为JSON对象的单个JSON数组返回的查询结果。
不,我想单独处理那些穿着管道的时尚。这怎么能在Node-RED中实现?
非常感谢!
JSON
[{
"id": "c8342b2a.bf0df",
"type": "cloudant in",
"z": "2f0a54f6.110ccc",
"service": "nokeredrkie-cloudantNoSQLDB",
"cloudant": "",
"name": "",
"database": "tweets",
"search": "_all_",
"design": "",
"index": "",
"x": 295.70001220703125,
"y": 450.9333190917969,
"wires": [
["5e83a34.48cdd5c"]
]
}, {
"id": "c9411e75.2b1b7",
"type": "debug",
"z": "2f0a54f6.110ccc",
"name": "",
"active": true,
"console": "false",
"complete": "payload",
"x": 646.699951171875,
"y": 470.7333679199219,
"wires": []
}, {
"id": "3f1d2018.8f5ec8",
"type": "inject",
"z": "2f0a54f6.110ccc",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": true,
"x": 126.70001220703125,
"y": 472.6666564941406,
"wires": [
["c8342b2a.bf0df"]
]
}, {
"id": "5e83a34.48cdd5c",
"type": "function",
"z": "2f0a54f6.110ccc",
"name": "",
"func": "//msg.payload = JSON.parse(msg.payload);\nmsg.payload = msg.payload[1].tweet.user.screen_name;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 444.70001220703125,
"y": 489.4000549316406,
"wires": [
["c9411e75.2b1b7"]
]
}]
JSON.parse该字符串,然后使用数组方法 –
如果我理解正确,你想要移动单个对象到一个新的变量。我对吗? – Rajesh