Mat*_*s S 12 javascript json text-to-speech stringify
以下示例显示JSON.stringify()返回"{}"SpeechSynthesisVoice对象的字符串:
var voiceObject = window.speechSynthesis.getVoices()[0];
JSON.stringify(voiceObject); //returns "{}"?
Run Code Online (Sandbox Code Playgroud)
完整示例:JSFiddle
它为什么会返回,"{}"而不是像"{voiceURI: "Google Deutsch", name: "Google Deutsch", lang: "de-DE", localService: false, default: false}"什么?
请注意,上面的示例不适用于chrome或iOS; 它针对的是Mozilla Firefox.
小智 6
TJ Crowder 的答案对我有用,我正在创建我的对象,如下所示:
Object.defineProperties(completeObj, {
[attributeName]: {
value: finalValue
}
});
Run Code Online (Sandbox Code Playgroud)
我为此进行了更改,问题解决了:
Object.defineProperties(completeObj, {
[attributeName]: {
value: finalValue,
enumerable: true
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7470 次 |
| 最近记录: |