我正在尝试从此api获取json数据:http ://chartapi.finance.yahoo.com/instrument/1.0/NFLX/chartdata;type=quote;range=1d/json而且我不知道如何获取放入返回的finance_charts_json_callback()中。
我正在使用Angular 2的http.get():
loadData() {
return this.http
.get(this.url)
.map((res) => res.json())
.subscribe((data) => console.log(data));
}
到达时=> res.json()
,将引发以下错误:
例外:SyntaxError:意外的令牌i
在这种情况下,您需要将JSONP与回调名称JSONP_CALLBACK一起使用:
loadData() {
this.jsonp.get(this.url)
.map(res => res.json())
.subscribe(data => console.log(data));
}
url
应该在哪里http://chartapi.finance.yahoo.com/instrument/1.0/NFLX/chartdata;type=quote;range=1d/json/?callback=JSONP_CALLBACK
,注意callback=JSONP_CALLBACK
部分。
当然,请记住使用引导应用程序bootstrap(App, [JSONP_PROVIDERS])
并Jsonp
从angular2/http
模块导入服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句