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?
Problem fixed by replacing the following code:
var data = message.records;
with:
var data = message.get('records');