如何在REST客户端中检索和显示JSON对象?

时间:2016-03-15 22:11:13

标签: json node.js rest

我正在尝试学习节点和JavaScript。我已经实现了使用节点模块来检索列车行程时间。

我可以在命令行中检索和显示时间,但我无法在RESTFUL客户端中显示。有没有人对如何在RESTFUL客户端中显示所有电影有任何建议?

//GET ALL TRAIN TIMES
router.route('/train_times')

//get all the times (accessed at GET http://localhost:8000/api/times)
.get(function(req, res) {

    cw.times(function(err, res, json){

        var times = json.train;

        //It is here i try and display the train times
        res.json(times);

        for (index = 0; index < time.length; ++index) {
          console.log(time[index].data);
        }

    }); 

});

1 个答案:

答案 0 :(得分:1)

问题是回调函数重用了变量res的名称。尝试使用其他名称:

cw.times(function(err, response, json){

    var times = json.films;

    //It is here i try and display the train times
    res.json(times);

});