node when using node to get GBK encoded data, NODEJS only support Utf-8,node does not provide native support for conversion encoding, there is a module iconv capable of this matter, but need local method, VC + + library support. There is a foreign Daniel wrote a pure JavaScript decoding module: Iconv-lite, you can implement the encoding conversion, using the following methods:
var http = require (" http "); var iconv = require ( "iconv-lite" ); var url = "http://hq.sinajs.cn/list=sh600595" ; var req = http.request (URL, function { Res.on (, function { data = Iconv.decode (data, ); Console.log ( +data); });}); Req.end ();
This is a get Sina on the stock market API,GBK encoded, if not converted, Chinese cannot output, as follows:
After using Iconv-lite, that is, after the Iconv.decode method, the output is as follows:
node. js conversion GBK Encoding-Iconv-lite