[英]Angular6 Get method response “_isScalar”:false,“source”
我正在尝试在html页面上显示json数据。 服务器上的数据向我显示json数据,但是当我尝试在页面上显示它时,它为我提供了此数据
{“ _isScalar”:false,“源”:{“ _ isScalar”:false,“源”:{“ _ isScalar”:false,“源”:{“ _ isScalar”:true,“值”:{“ url”:“ https://feeds.citibikenyc.com/stations/stations.json “,” body“:null,” reportProgress“:false,” withCredentials“:false,” responseType“:” json“,” method“:” GET“ ,“标头”:{“ normalizedNames”:{},“ lazyUpdate”:null,“标头”:{}},“ params”:{“ updates”:null,“ cloneFrom”:null,“ encoder”:{} ,“ map”:null},“ urlWithParams”:“ https://feeds.citibikenyc.com/stations/stations.json ”}“,” scheduler“:null},” operator“:{” concurrent“:1}} ,“操作员”:{}},“操作员”:{}}
我获取数据的代码是
import { HttpClient} from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class GetdataService {
posts : any;
readonly ROOT_URL ="https://feeds.citibikenyc.com/stations/stations.json";
constructor(private http: HttpClient ) { }
getPosts()
{
this.posts = this.http.get(this.ROOT_URL );
return JSON.stringify(this.posts);
}
}
this.http.get()
不返回数据,而是可观察的,必须订阅:
getPosts() {
this.http.get(this.ROOT_URL)
.subscribe((data) => {
//DO STUFF HERE
});
}
其次,虽然在修复observable-stuff之后不需要解码JSON,但您可以使用JSON.parse()
而不是JSON.stringify
来解码JSON。 stringify
将对象转换为字符串(与您想要的相反)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.