[英]ArangoDB Foxx Repository JSON Parsing issue
I've a problem in parsing a JSON message in my Foxx application in ArangoDB. 我在ArangoDB的Foxx应用程序中解析JSON消息时遇到问题。
This is the code for the "post" in the controller: 这是控制器中“ post”的代码:
controller.post('/', function (req, res) {
var message = req.params("testCollection");
var data = message.records;
for(var i in data) {
var imei = data[i].imei;
var timestamp = data[i].timestamp;
....other stuff here using place and timestamp
}
}
This is the JSON message: 这是JSON消息:
{
"records": [
{
"timestamp": "2001/05/09",
"imei": "123456789012345",
"gpsData": {
"lat": 1001,
"lon": 1002,
"altitude": 1003,
"speed": 1004
},
"io": [
{"key": "IO1", "value": 1},
{"key": "IO2", "value": 2},
{"key": "IO3", "value": 3},
{"key": "IO4", "value": 4},
{"key": "IO5", "value": 5},
{"key": "IO6", "value": 6},
{"key": "IO7", "value": 7}
]
}
]
}
The imei
is then used as parameter for a query but I can't get any response. 然后将
imei
用作查询的参数,但我无法获得任何响应。 If I hardcode the imei
I can get the proper document from the collection. 如果我对
imei
硬编码,则可以从集合中获取正确的文档。
Is there anything wrong in the above code to parse the JSON? 上面的代码解析JSON有什么问题吗?
Problem fixed by replacing the following code: 通过替换以下代码解决了问题:
var data = message.records;
with: 有:
var data = message.get('records');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.