gpt4 book ai didi

Angular6 获取方法响应 "_isScalar":false ,"source"

转载 作者:行者123 更新时间:2023-12-03 19:46:24 26 4
gpt4 key购买 nike

我正在尝试在 html 页面上显示 json 数据。服务器上的数据向我显示了 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":{}}



我获取数据的代码是
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()不返回数据,而是返回一个 observable,您必须订阅:

getPosts() {
this.http.get(this.ROOT_URL)
.subscribe((data) => {
//DO STUFF HERE
});
}

Readmore

其次,虽然在修复 observable-stuff 后不需要解码 JSON,但您可以使用 JSON.parse() 解码 json。不是 JSON.stringify . stringify将对象转换为字符串(与您想要的完全相反)。

关于Angular6 获取方法响应 "_isScalar":false ,"source",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52106855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com