[英]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.