var url = 'http://www.googleapis.com/customsearch/v1?q=foo&searchType=image';
window.fetch(url)
.then(decode)
.catch(err => console.log(err));
function decode(r) {
// r.body is a ReadableByteStream - how do I decode it to a string?
}
r.body
是ReadableByteStream
- 如何将其解码为字符串?
decode
是正确的术语吗?
答案 0 :(得分:1)
为此目的内置解码器:
window.fetch(url)
.then(r => r.text())
.catch(err => console.log(err));