【问题标题】:node.js websocket, converting JSON datanode.js websocket,转换JSON数据
【发布时间】:2017-12-01 14:03:23
【问题描述】:

使用 node.js 我运行以下代码:

var autobahn = require('autobahn');
var wsuri = "wss://api.poloniex.com";
var connection = new autobahn.Connection({
  url: wsuri,
  realm: "realm1"
});

connection.onopen = function (session) {
        function marketEvent (args,kwargs) {
                console.log(args);
        }
        function tickerEvent (args,kwargs) {
                console.log(args);
        }
        function trollboxEvent (args,kwargs) {
                console.log(args);
        }
        session.subscribe('USDT_BTC', marketEvent);

}

connection.onclose = function () {
  console.log("Websocket connection closed");
}

connection.open();

并通过 push-API JSON-Data 恢复:

[ { type: 'orderBookModify',
    data: { type: 'bid', rate: '2357.77000002', amount: '0.82956965' } } ]

现在我想处理数据,是否可以将其存储到 mysql 或仅使用 JSON-Array 序列声明一个变量?

【问题讨论】:

  • is it possible to store it into mysql:是的。 declare a variable with just a sequence of the JSON-Array 不确定你对 a sequence of JSON-Array 的意思
  • 我只想获取一个变量的汇率和另一个变量的金额
  • 为此使用 JSON.parse。
  • [ { type: 'orderBookModify', data: { type: 'bid', rate: '2357.77000002', amount: '0.82956965' } } ] 是json数组还是字符串?跨度>
  • 两者,json只是特定格式的字符串数据

标签: javascript json node.js websocket push-api


【解决方案1】:

您可以使用 JSON.stringify 将 JSON 转换为字符串,然后将其保存到 MySQL。但是,我不确定您所说的 JSON 数组序列是什么意思

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-05
    • 2013-06-24
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2015-08-27
    相关资源
    最近更新 更多