我有一个与端点对话的Javascript UI。端点以JSON对象数组的形式返回密码质询。每个对象都有密码中的字符索引和字符代码点值。
[{"index":3,"nValue":101},{"index":5,"nValue":114},{"index":6}]我正在努力将代码点转换回字母。我得到了RangeError异常。我不确定为什么不能将值解析为number并将其传递给fromCharCode方法。
for(var i = 0;i<result.length;i++){
console.log(typeof result[i].nValue); //prints string
console.log('returnVal=*'+result[i].nValue+'*'); //prints *e*
var intChar = parseInt(result[i].nValue);
console.log(typeof intChar); //prints number
console.log('intChar=*'+intChar+'*'); //prints *NaN*
console.log('converted='+String.fromCharCode(result[i].nValue)); //empty string
console.log('converted='+String.fromCodePoint(result[i].nValue)); //trows range exception
}https://stackoverflow.com/questions/47632533
复制相似问题