因为在 Request 和 Response 中都包含 Body 的实现,所以包含以下类型:
ArrayBufferArrayBufferView (Uint8Array and friends)Blob/FilestringURLSearchParamsFormData在 fetch 中实现了对应的方法,并返回的都是 Promise 类型。那如何获取到我们的json数据呢?
这样处理返回的数据类型就会变的特别地方便,如处理 json 格式的数据:
var myRequest = new Request('http://api.com/products.json'); fetch(myRequest).then(function(response) { return response.json().then(function(json) { for(i = 0; i < json.products.length; i++) { var name = json.products[i].Name; var price = json.products[i].Price; // do something more... } }); });