无法从角度6的json响应分配值

时间:2018-08-04 00:00:24

标签: node.js angular

我尝试从GET请求中收到响应后,为NodeJS服务器分配值,但是我一直收到undefined,而且我不明白为什么。

这些是我要为其分配值的变量:

 movie:any
 showHalls:any 

.subscribe函数内部的ngOnInit

ngOnInit() {
    this.showService.getShowByMovieId(this.route.snapshot.params['id'])
    .subscribe(
      data=> 
      { 
       this.showHalls = data.showsHall
       this.movie     = data.movie;

      },
  );

服务器内部的Get请求:

getShowByMovieId(id): Observable<any>{
    return this.http.get(this.getShowByMovieIdUrl + id)
}

NodeJs中的路由

router.get('/showbymovieid:id', function (req, res, next) {
    Shows.find({ movie: mongoose.Types.ObjectId(req.params.id) }).populate('movie').populate('showsHall').exec(function (err, foundShow) {
        if (err) return next(err)
        res.json(foundShow)
    })
})

Json文件

[
    {
        "showsHall": [
            {
                "_id": "5b64cb758ad5f81a6cb7e6ae",
                "hallName": "Big Hall",
                "rows": 10,
                "seats": 15,
                "__v": 0
            }
        ],
        "movie": [
            {
                "associatedToShow": true,
                "_id": "5b64d3968a0b995afc12f03d",
                "movieName": "Whitny",
                "directorName": "Kevin Macdonald",
                "movieDescription": "Nice Movie",
                "movieImg": "uploads\\474064ac3999bda872d37a992bdd01dd",
                "updated_date": "2018-08-03T22:13:42.944Z",
                "__v": 0
            }
        ],
        "takenSeats": [],
        "_id": "5b64d3ca8a0b995afc12f03f",
        "showDate": "8/5/2018",
        "showStartTime": "1:14 AM",
        "showEndTime": "1:14 AM",
        "__v": 0
    }
]

这是我在控制台上记录数据时的样子

enter image description here

1 个答案:

答案 0 :(得分:1)

JSON为test ]> select convert(binary(convert(convert(unhex('312E2058C3A3C281C2A6C3A3E2809AE284A2C3A6C593E280B0C3A5C290C28DC3A3C281C2AA') using utf8 ) using latin1 )) using utf8 ); +--------------------------------------------------------------------------------------------------------------------------------------------------------------+ | convert(binary(convert(convert(unhex('312E2058C3A3C281C2A6C3A3E2809AE284A2C3A6C593E280B0C3A5C290C28DC3A3C281C2AA') using utf8 ) using latin1 )) using utf8 ) | +--------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 1. Xで有名な | +--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) ,但您将其视为test > select hex(convert (convert(binary('1. Xで有名な ') using latin1 ) using utf8 )) ; +---------------------------------------------------------------------------------+ | hex(convert (convert(binary('1. Xで有名な') using latin1 ) using utf8 )) | +---------------------------------------------------------------------------------+ | 312E2058C3A3C281C2A6C3A3E2809AE284A2C3A6C593E280B0C3A5C290C28DC3A3C281C2AA | +---------------------------------------------------------------------------------+ 1 row in set (0.00 sec)

在可观察到的API调用订阅中,尝试

Array