0
client.query("select * from rooms where token = ?", [data.token], function(err, results, fields) {
 callback(results);
 console.log(results); 
});

这是一个以数组形式返回结果的查询。如何获得必要的字段?

4

1 回答 1

0

查看您的评论,如果 json 对象是-:

[
   {
      "bump":"1376149484",
      "user":"alex",
      "token":"11569",
      "active":0
   }
]

您可以像这样遍历对象-:

for (var i in results)
{
  console.log('bump = ' + results[i].bump);
  console.log('user = ' + results[i].user);
  console.log('token = ' + results[i].token);
  console.log('active = ' + results[i].active);
}
于 2013-08-10T16:16:17.023 回答