ArangoDB Foxx存储库JSON解析问题(ArangoDB Foxx Repository JSON Parsing issue)
我在ArangoDB中的Foxx应用程序中解析JSON消息时遇到问题。
这是控制器中“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 } }这是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} ] } ] }然后将imei用作查询的参数,但我无法得到任何响应。 如果我对imei硬编码,我可以从该集合中获取正确的文档。
上面的代码解析JSON有什么问题吗?
I've a problem in parsing a JSON message in my Foxx application in ArangoDB.
This is the code for the "post" in the controller:
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:
{ "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. If I hardcode the imei I can get the proper document from the collection.
Is there anything wrong in the above code to parse the JSON?
最满意答案
通过替换以下代码修复问题:
var data = message.records;有:
var data = message.get('records');Problem fixed by replacing the following code:
var data = message.records;with:
var data = message.get('records');更多推荐
发布评论