1.处理回显乱码
res.write("<head><meta charset=‘utf-8‘></head>");
2.处理传参乱码
querystring.escape(str)
escape可使传入的字符串进行编码
querystring.escape
querystring.escape("name=慕白"); /* return: ‘name%3D%E6%85%95%E7%99%BD‘ */
querystring.unescape(str)
unescape方法可将含有%的字符串进行解码
querystring.unescape
querystring.unescape(‘name%3D%E6%85%95%E7%99%BD‘); /* return: ‘name=慕白‘ */
具体:http://www.cnblogs.com/whiteMu/p/5986297.html
3.与编码相关的代码(朕没用上)
var encoding = require(‘encoding‘); var iconv = require(‘iconv-lite‘); console.log(encoding.convert("%E7%9A%84%E5%A3%AB%E9%80%9F%E9%80%92", "utf-8"));
console.log(iconv.decode(‘%E7%9A%84%E5%A3%AB%E9%80%9F%E9%80%92‘, ‘utf-8‘));
时间: 2024-10-01 06:44:48