ArangoDB Foxx存储库JSON解析问题(ArangoDB Foxx Repository JSON Parsing issue)

编程入门 行业动态 更新时间:2024-10-04 23:29:10
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');

更多推荐

本文发布于:2023-08-07 13:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSON   Foxx   ArangoDB   issue   Parsing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!