[英]What is the return type of executeScript() method of JavascriptExecutor?
[英]What is the return type of the json method of a response?
我看到一些Angular 2的例子,它们将http
的响应转换为JavaScript对象,如下所示:
http.get("http://....").subscribe(
response => {
let result = response.json();
},
error => {
console.log('cannot get api');
}
);
我还看到一些例子,其中指出json()
方法返回一个无极,这需要该函数被封闭在then
,得到的结果:
response.json().then(result => ({
///
});
为什么一个使用then
另一个不使用? 什么是json
的价值回报,我应该使用哪些?
您看到response.json()
返回Promise
的示例是Fetch API的一部分,它仍然是实验性的: https : //developer.mozilla.org/en-US/docs/Web/API/Response
Body.json()
获取响应流并将其读取完成。 它返回一个使用JSON对象解析的promise。
您看到的另一个示例来自Angular的实现,它直接返回数据而不是Promise
: https : //github.com/angular/angular/blob/master/packages/http/src/body.ts#L26
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.