[英]Angular6 Get method response “_isScalar”:false,“source”
I am trying to show the json data on the html page. 我正在尝试在html页面上显示json数据。 The data on the server shows me json data but when i try to show it on page it gives me this data
服务器上的数据向我显示json数据,但是当我尝试在页面上显示它时,它为我提供了此数据
{"_isScalar":false,"source":{"_isScalar":false,"source":{"_isScalar":false,"source":{"_isScalar":true,"value":{"url":" https://feeds.citibikenyc.com/stations/stations.json ","body":null,"reportProgress":false,"withCredentials":false,"responseType":"json","method":"GET","headers":{"normalizedNames":{},"lazyUpdate":null,"headers":{}},"params":{"updates":null,"cloneFrom":null,"encoder":{},"map":null},"urlWithParams":" https://feeds.citibikenyc.com/stations/stations.json "},"scheduler":null},"operator":{"concurrent":1}},"operator":{}},"operator":{}}
{“ _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}} ,“操作员”:{}},“操作员”:{}}
my code for getting the data is 我获取数据的代码是
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()
doesn't return data but rather an observable, that you have to subscribe to: this.http.get()
不返回数据,而是可观察的,必须订阅:
getPosts() {
this.http.get(this.ROOT_URL)
.subscribe((data) => {
//DO STUFF HERE
});
}
Secondly, while it shouldn't be needed to decode JSON after you fix the observable-stuff, you decode json with JSON.parse()
not JSON.stringify
. 其次,虽然在修复observable-stuff之后不需要解码JSON,但您可以使用
JSON.parse()
而不是JSON.stringify
来解码JSON。 stringify
converts the object into string (the exact opposite of what you wanted). stringify
将对象转换为字符串(与您想要的相反)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.