这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
TextDecoder.prototype.decode()
方法返回
DOMString
containing the text, given in parameters, decoded with the specific method for that
TextDecoder
对象。
b1 = decoder.decode(buffer, options);
b2 = decoder.decode(buffer);
b3 = decoder.decode();
buffer
可选
ArrayBuffer
或
ArrayBufferView
containing the text to decode.
选项
可选
TextDecodeOptions
dictionary with the property:
stream
布尔
flag indicating that additional data will follow in subsequent calls to decode(). Set to true if processing the data in chunks, and false for the final chunk or if the data is not chunked. It defaults to false.
This example encodes and decodes the euro symbol, €.
<p>Encoded value: <span id="encoded-value"></span></p> <p>Decoded value: <span id="decoded-value"></span></p>
const encoder = new TextEncoder();
const array = encoder.encode('€'); // Uint8Array(3) [226, 130, 172]
document.getElementById('encoded-value').textContent = array;
const decoder = new TextDecoder();
const str = decoder.decode(array); // String "€"
document.getElementById('decoded-value').textContent = str;
| 规范 | 状态 | 注释 |
|---|---|---|
|
编码
The definition of 'TextDecoder.decode()' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
decode
|
Chrome 38 | Edge ≤79 |
Firefox
19
|
IE 不支持 No | Opera 25 | Safari 10.1 | WebView Android 38 | Chrome Android 38 |
Firefox Android
19
|
Opera Android Yes | Safari iOS 10.3 | Samsung Internet Android 3.0 |
完整支持
不支持
见实现注意事项。
TextDecoder
interface it belongs to.
TextDecoder
decode()