admin管理员组文章数量:1425760
I am reading ng-book about Angular 2, there is a piece of code:
return this.http.get(queryUrl)
.map((response: Response) => {
return (<any>response.json()).items.map(item => {
// console.log("raw item", item); // unment if you want to debug
return new SearchResult({
id: item.id.videoId,
title: item.snippet.title,
description: item.snippet.description,
thumbnailUrl: item.snippet.thumbnails.high.url
});
});
});
What is .json()
in line 3? I have googled around, but cannot find any description for this method.
I am reading ng-book about Angular 2, there is a piece of code:
return this.http.get(queryUrl)
.map((response: Response) => {
return (<any>response.json()).items.map(item => {
// console.log("raw item", item); // unment if you want to debug
return new SearchResult({
id: item.id.videoId,
title: item.snippet.title,
description: item.snippet.description,
thumbnailUrl: item.snippet.thumbnails.high.url
});
});
});
What is .json()
in line 3? I have googled around, but cannot find any description for this method.
1 Answer
Reset to default 8The Http
object you are using returns an Observable<Response>
object whenever you call any request, in this case, a get
.
The Response
class has method called .json()
which attempts to return the body of the Response
object as a parsed JSON
object in order to make it easier to work with it.
The items
is just assuming that the response body has an items property, so the get
he's doing is expecting something like this to be returned:
{ items: ... }
Take a look at: https://angular.io/docs/ts/latest/api/http/Http-class.html
and https://angular.io/docs/ts/latest/api/http/Response-class.html
本文标签: javascriptWhat is quotitemsquot and quotjson()quotStack Overflow
版权声明:本文标题:javascript - What is ".items" and ".json()" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745451335a2658900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论