我如何将json数据添加到node.js中的mysql数据库中

编程入门 行业动态 更新时间:2024-10-12 10:19:16

我如何将json数据添加到node.js中的mysql<a href=https://www.elefans.com/category/jswz/34/1771342.html style=数据库中"/>

我如何将json数据添加到node.js中的mysql数据库中

我要从;

我想用json数据中的id,名称,用户名和电子邮件填充mysql数据库。我正在使用一个名为“ request”的节点模块来读取在线json api


const db = mysql.createConnection({
   host: 'localhost',
   user: 'root',
   password: '',
   database: 'nodemysql'
});
connect
db.connect((err) => {
   if (err) {
       throw err
   }
   console.log('MySql Connected...');

});
app.get('/populate', (req, res) => {
   request({
       url: "",
       json: true
   }, (err, res, body) => {
       res.send(body);
   });
})

这是json API中项目的两个示例

  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "[email protected]",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "[email protected]",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  }

我只需要将id,名称,用户名和电子邮件添加到mysql数据库中,作为每个用户的行的列

我要从,我想用json数据中的id,名称,用户名和电子邮件填充mysql数据库。我正在使用一个名为...

回答如下:

假设

更多推荐

我如何将json数据添加到node.js中的mysql数据库中

本文发布于:2024-05-07 21:16:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   如何将   数据   json   node

发布评论

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

>www.elefans.com

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