parsing调用后JavaScript JavaScriptJS
我正在与fiware合作,当进行订阅时,这些信息被发送到我的rest API中定义的一个方法,并且我想将这些信息保存在我的数据库中。
从ContextBroker获得的信息是:
{ "subscriptionId": "5a268a598dc68904bbc7b3cf", "originator": "localhost", "contextResponses": [ { "contextElement": { "type": "Temperature", "isPattern": "false", "id": "S_Temp001", "attributes": [ { "name": "Tem_int", "type": "float", "value": 22, "metadatas": [ { "name": "accuracy", "type": "Float", "value": 44} ] }, { "name": "Tem_out", "type": "Integer", "value": 22 } ] }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
我在我的API中定义的方法是这样的:
// insertBD function postinsertbdarduino1 (req, res) { var inver = { fiwareServicePath: String, entityId: String, entityType: String, attrName: String, attrType: String, attrValue: String, attrMd: String }; var params = req.body; // check if the pass && name etc arrive and encrypt // Assign values to the user object //inver.entityId = params.entityId; inver.fiwareServicePath = params.fiwareServicePath; inver.entityId = params.id; inver.entityType = params.type; inver.attrName = params.name; inver.attrType = params.attrType; inver.attrValue = params.attrValue; inver.attrMd = params.attrMd; pool.getConnection (function (err, connection) { if (err) { console.log ('Error requesting a connection:' + err); return; } console.log ("connection tests"); // if we want to add other conditions in the where would it be to put the fields and? and then to what is it equivalent // 'SELECT * FROM all WHERE id =? AND username =? ', [Req.params.id, user.username], function (err, rows) connection.query ('INSERT INTO inver SET?', [inver], function (err, rows) { if (err) { throw err; console.log ('Error when connecting' + error); } else { res.status (200) .json (rows); } }); // so that it can be reused by the pool, it is important to "release" it connection.release (); }); }
现在我只是通过id,types和名称。
但是他把我的logging保存在空的数据库中。
我怎样才能解决这个问题?
感谢问候。
EDIT1
我刚刚启动了JSON,我的API方法更改了subscriptionId值inver.entityId = params.subscriptionId;
如果数据到达,但我需要恢复数据" type ":" Temperature "
" id ":" S_Temp001 ",
{ "name": "Tem_int", "type": "float", "value": 22, "metadatas": [ { "name": "accuracy", "type": "Float", "value": 44} ] }, { "name": "Tem_out", "type": "Integer", "value": 22 }
我怎样才能到达JSON的那一部分?
谢谢。
EDIT2
好,
我修改这个问题。
我如何在NODEJS JavaScript中运行这个JSON:
{ "subscriptionId": "5a268a598dc68904bbc7b3cf", "originator": "localhost", "contextResponses": [ { "contextElement": { "type": "Temperature", "isPattern": "false", "id": "S_Temp001", "attributes": [ { "name": "Tem_int", "type": "float", "value": 2, "metadatas": [ { "name": "accuracy", "type": "Float", "value": 2} ] }, { "name": "Tem_out", "type": "Integer", "value": 1 } ] }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
问候,谢谢。