将rowdatapacket转换为array,如何将mysql node.js api rowdatapacket转换为array,将字符串转换为array

时间:2019-01-04 14:21:08

标签: javascript mysql arrays node.js string

请帮助我将rowdatapacket转换为数组数组或嵌套数组

在此处输入代码

router.get('/getPosts/:user_id', (req, res, next) => {

connection.query('SELECT * FROM files WHERE user_id = ?', [req.params.user_id], (err, rows, fields) => {
  if (!err) {

    resultArray = JSON.parse(JSON.stringify(rows));

    console.log(resultArray);

    return res.status(200).send(resultArray);
  } else {
    console.log(err);
    return res.status(404).send('Sorry user_id does not exits');
  }
 })
});

输出

1 个答案:

答案 0 :(得分:0)

输出:

{post_id:17     user_id:1     描述:“嗨,你好吗”,     文件名:“ iron_man_5k_2.jpg,iron_man_captain.jpg”,     模仿类型:“ image / jpeg,image / jpeg”,     大小:'5696459,180',     saved_name:      '1546438737564_iron_man_5k_2.jpg,1546438737672_iron_man_captain.jpg',     文件路径:      'uploads1546438737564_iron_man_5k_2.jpg,uploads1546438737672_iron_man_captain.jpg',     创建:'2019-01-02T14:18:57.000Z'}