我的目標是將Fields
從下面的JSON對象寫入MySQL數據庫。如何獲得多行的json對象
var dataRow = {
Table: "promosbudget",
Fields:[{
ManagerID: "Jose",
UserID: "ife",
Budget: "50000",
Year: "2015"
},
{
ManagerID: "Jose",
UserID: "fgs",
Budget: "50000",
Year: "2015"
},
{
ManagerID : "Jose",
UserID : "brz",
Budget : "50000",
Year : "2015"
}]
};
我使用這個命令來接收和寫入數據:
app.post('/paramsjson', jsonParser, function(req, res) {
conMySQL.query('INSERT INTO ' + req.body.Table + ' SET ?',req.body.Fields,
function(err,result) {
console.log(result);
}
);
});
的問題是,我只能寫在第一行的JSON,其他2行被省略。
我想問是否有一個推薦的方法來做到這一點,當我需要導出一個大的JSON對象(100.000行),是否有必要做一個循環,並順序讀取每一行?
在此先感謝您的幫助!
您是易受[SQL注入攻擊(http://bobby-tables.com),並且需要循環上JSON數據結構,並插入每個單獨的這些「字段」子對象。 –