arrays - 如何在nodejs上提取数组

标签 arrays node.js api

我正在制作用于显示用户信息的API,所以我编写了这样的代码

res.json({"Status" : true , "User" : rows });

然后我得到结果

    {
      "Status": true,
      "User": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

但我想要这样的结果

    {
      "Status": true,
      "userid": 821786,
      "fullname": "undefined"
    }

我该怎么做?

我试过了

res.json({"Status" : true ,"Type":"Google",  rows });

但它给了我

    {
      "Status": true,
      "rows": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

我可以确定只会查询一个结果,所以我不想使用数组

最佳答案

试试这个:

var result = rows[0];
result.Status = true;
res.json(result);

关于arrays - 如何在nodejs上提取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35647756/

相关文章:

angular - 'Employee' 仅指类型,但在此处用作值。ts(2693)

php - 解码 laravel 4 Input::json()

node.js - Vue.js 服务卡在 40% 如何恢复?

php - 推文中的西里尔符号

c# - LINQ to Entities 不支持 LINQ 表达式节点类型 'ArrayIndex'

javascript - 如何在页面刷新时随机交换图像横幅?

c++ - 如何在 Node.js Addon 中返回 JSON 内容

javascript - SVG路径优化

JavaScript 2D 数组未捕获类型错误

c++ - 用于初始化 2D std::array 成员的初始化列表