我正在制作用于显示用户信息的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/