我在从节点中的流反序列化时遇到问题(特别是来自比特币 GOX 交易所的定价提要)。基本上到达了一个完整且经过验证的 JSON块。这是代码:
var gox = require('goxstream');
var fs = require('fs');
var options = {
currency: 'AUD',
ticker: true,
depth: false
};
var goxStream = gox.createStream(options);
goxStream.on('data', function(chunk) {
console.log(JSON.parse(chunk));
});
尝试解析它时,我得到以下信息
undefined:0
^
SyntaxError: Unexpected end of input
有任何想法吗?我已经包含了一个示例块:
> {"channel": "eb6aaa11-99d0-4f64-9e8c-1140872a423d", "channel_name":
> "ticker.BTCAUD", "op": "private", "origin": "broadcast", "private":
> "ticker", "ticker": {
> "high": {
> "value": "121.51941",
> "value_int": "12151941",
> "display": "AU$121.51941",
> "display_short": "AU$121.52",
> "currency": "AUD"
> },
> "low": {
> "value": "118.00001",
> "value_int": "11800001",
> "display": "AU$118.00001",
> "display_short": "AU$118.00",
> "currency": "AUD"
> },
> "avg": {
> "value": "119.58084",
> "value_int": "11958084",
> "display": "AU$119.58084",
> "display_short": "AU$119.58",
> "currency": "AUD"
> },
> "vwap": {
> "value": "119.80280",
> "value_int": "11980280",
> "display": "AU$119.80280",
> "display_short": "AU$119.80",
> "currency": "AUD"
> },
> "vol": {
> "value": "249.73550646",
> "value_int": "24973550646",
> "display": "249.73550646\u00a0BTC",
> "display_short": "249.74\u00a0BTC",
> "currency": "BTC"
> },
> "last_local": {
> "value": "118.50000",
> "value_int": "11850000",
> "display": "AU$118.50000",
> "display_short": "AU$118.50",
> "currency": "AUD"
> },
> "last_orig": {
> "value": "108.99500",
> "value_int": "10899500",
> "display": "$108.99500",
> "display_short": "$109.00",
> "currency": "USD"
> },
> "last_all": {
> "value": "118.79965",
> "value_int": "11879965",
> "display": "AU$118.79965",
> "display_short": "AU$118.80",
> "currency": "AUD"
> },
> "last": {
> "value": "118.50000",
> "value_int": "11850000",
> "display": "AU$118.50000",
> "display_short": "AU$118.50",
> "currency": "AUD"
> },
> "buy": {
> "value": "118.50000",
> "value_int": "11850000",
> "display": "AU$118.50000",
> "display_short": "AU$118.50",
> "currency": "AUD"
> },
> "sell": {
> "value": "119.99939",
> "value_int": "11999939",
> "display": "AU$119.99939",
> "display_short": "AU$120.00",
> "currency": "AUD"
> },
> "item": "BTC",
> "now": "1376715241731341" }}
你可以在这里验证它:http: //jsonlint.com
另外值得一提的是,我已经尝试过解析和删除转义字符。还尝试了几个不同的序列化器,结果相同