node.js中的buffer.toJSON方法使用说明
作者:bea
方法说明: 将buffer对象 转换成json格式。 语法: 代码如下: buffer.toJSON() 接收参数: 无 例子: 代码如下: var buf = new Buffer('test'); var json = JSON.stringify(buf); console.log(json); // '{"type":"Buffer","data":[116,101,115,116]}' var copy = JSON.parse(json,
方法说明:
将buffer对象 转换成json格式。
语法:
代码如下:
buffer.toJSON()
接收参数:
无
例子:
代码如下:
var buf = new Buffer('test');
var json = JSON.stringify(buf);
console.log(json);
// '{"type":"Buffer","data":[116,101,115,116]}'
var copy = JSON.parse(json, function(key, value) {
return value && value.type === 'Buffer'
? new Buffer(value.data)
: value;
});
console.log(copy);
// <Buffer 74 65 73 74>
源码:
代码如下:
Buffer.prototype.toJSON = function() {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this, 0)
};
};
有用 | 无用
将buffer对象 转换成json格式。
语法:
代码如下:
buffer.toJSON()
接收参数:
无
例子:
代码如下:
var buf = new Buffer('test');
var json = JSON.stringify(buf);
console.log(json);
// '{"type":"Buffer","data":[116,101,115,116]}'
var copy = JSON.parse(json, function(key, value) {
return value && value.type === 'Buffer'
? new Buffer(value.data)
: value;
});
console.log(copy);
// <Buffer 74 65 73 74>
源码:
代码如下:
Buffer.prototype.toJSON = function() {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this, 0)
};
};
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- node.js中的fs.ftruncate方法使用说明
- node.js中的fs.fsyncSync方法使用说明
- node.js中的fs.writeSync方法使用说明
- node.js中的fs.write方法使用说明
- node.js中的http.createClient方法使用说明
- node.js中的http.get方法使用说明
- node.js中的http.createServer方法使用说明
- node.js中的fs.writeFileSync方法使用说明
- node.js中的http.response.addTrailers方法使用说明
- node.js中的http.response.writeHead方法使用说明
- node.js中的http.response.getHeader方法使用说明
- node.js中的http.response.write方法使用说明
- node.js中的http.response.end方法使用说明
- node.js中的http.response.setHeader方法使用说明
- node.js中的http.response.removeHeader方法使用说明
- node.js中的http.request方法使用说明
- node.js中的buffer.copy方法使用说明
- node.js中的buffer.fill方法使用说明
- node.js中的buffer.length方法使用说明