我得到responseBody
未定义,但我在msg_body中获得了订阅响应。问题与responseBody
有什么关系?
let stomp_subscription = this._stompService.subscribe('/topic/queue');
stomp_subscription.map((message: Message) => {
return message.body;
}).subscribe((msg_body: string) => {
console.log(`Received: ${msg_body}`);
this.responseBody = JSON.parse(msg_body);
console.log('RESPONSECODE' + this.responseBody.ResponseInfo.ResponseCode);
});
答案 0 :(得分:0)
您正在使用来自Observable的return
运算符的.map()
语句。因此,该值不会传递给针对Observable的下一个.subscribe()
调用。你能试试下面的代码
let stomp_subscription = this._stompService.subscribe('/topic/queue');
stomp_subscription.map((message: Message) => message.body )
.subscribe((msg_body: string) => {
console.log(`Received: ${msg_body}`);
this.responseBody = JSON.parse(msg_body);
console.log('RESPONSECODE' + this.responseBody.ResponseInfo.ResponseCode);
});