API仅返回一个结果的JSON数组

时间:2017-05-03 01:29:49

标签: sql json node.js api

目前正在处理给定地址的API返回有关的信息。我们表中的一些行是重复的,但是因为有超过1500万我不能去找重复项。相反,我选择使用

    var query = `SELECT TOP 1 * from my_TABLE where..conditions`;

这确保只返回一行重复项。 问题是当它作为JSON发送回来时,它是一个带有一个对象的数组。

在Server.js文件中

    // create Request object
        var request = new sql.Request();
        // query to the database
        request.query(query, function (err, result) {

            if (err) {
                console.log("Error while querying database :- " + err);
                res.send(err);
            }
            else {
                    res.send(result)
            }

返回:

 [{
     Address:'our info'
   }]

有没有办法让它回复

{
 Address:'our info'
}

1 个答案:

答案 0 :(得分:0)

因为从DB中你已经得到了对象列表,即使只有一个项目。

当您尝试使用joshua@joshua-VirtualBox:~$ ffmpeg -i /media/sf_2017-04/SD_044/00007.MTS /media/sf_2017-04/SD_04/000007.mp4 ffmpeg version 0.8.17-4:0.8.17-0ubuntu0.12.04.2, Copyright (c) 2000-2014 the Libav developers built on Apr 1 2016 14:28:02 with gcc 4.6.3 The ffmpeg program is only provided for script compatibility and will be removed in a future release. It has been deprecated in the Libav project to allow for incompatible command line syntax improvements in its replacement called avconv (see Changelog for details). Please use avconv instead. Input #0, mpegts, from '/media/sf_2017-04/SD_044/00007.MTS': Duration: 00:01:17.07, start: 1.927822, bitrate: 25053 kb/s Program 1 Stream #0.0[0x1011]: Video: h264 (High), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 59.96 fps, 59.94 tbr, 90k tbn, 119.88 tbc Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s Stream #0.2[0x1200]: Data: [144][0][0][0] / 0x0090 File '/media/sf_2017-04/SD_04/000007.mp4' already exists. Overwrite ? [y/N] y [buffer @ 0x88772a0] w:1920 h:1080 pixfmt:yuv420p ffmpeg -i /media/sf_2017-04/SD_044/00007.MTS /media/sf_2017-04/SD_04/000007.mp4 ffmpeg version 0.8.17-4:0.8.17-0ubuntu0.12.04.2, Copyright (c) 2000-2014 the Libav developers built on Apr 1 2016 14:28:02 with gcc 4.6.3 The ffmpeg program is only provided for script compatibility and will be removed in a future release. It has been deprecated in the Libav project to allow for incompatible command line syntax improvements in its replacement called avconv (see Changelog for details). Please use avconv instead. Input #0, mpegts, from '/media/sf_2017-04/SD_044/00007.MTS': Duration: 00:01:17.07, start: 1.927822, bitrate: 25053 kb/s Program 1 Stream #0.0[0x1011]: Video: h264 (High), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 59.96 fps, 59.94 tbr, 90k tbn, 119.88 tbc Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s Stream #0.2[0x1200]: Data: [144][0][0][0] / 0x0090 File '/media/sf_2017-04/SD_04/000007.mp4' already exists. Overwrite ? [y/N] y [buffer @ 0x88772a0] w:1920 h:1080 pixfmt:yuv420p encoder 'aac' is experimental and might produce bad results. Add '-strict experimental' if you want to use it. 的第一个元素返回json时,它会按预期工作。