我正在尝试在JS中遵循此示例并将其转换为Java https://github.com/cryptoqween/cryptoqween.github.io/blob/master/streamer/current/stream.js
下面的代码来自文档:
var subscription = ['5~CCCAGG~BTC~USD', '5~CCCAGG~ETH~USD', '11~BTC', '11~ETH'];
socket.emit('SubAdd', { subs: subscription });
所以我怎么能在android studio中写这个,这就是我尝试过的
String[] subscription = {"5~CCCAGG~BTC~USD", "5~CCCAGG~ETH~USD", "11~BTC", "11~ETH"};
HashMap<String, String[]> maps = new HashMap<>();
Socket mSocket;
maps.put("subs", subscription);
try {
mSocket = IO.socket("https://streamer.cryptocompare.com/");
} catch (URISyntaxException e) {e.printStackTrace();}
mSocket.connect();
mSocket.on(Socket.EVENT_CONNECT, onConnect);
mSocket.on("m", onData);
这是我将物品发射到服务器的方式:
mSocket.emit("SubAdd", maps);
而且我不断从服务器收到错误消息“ 401〜BADFORMAT”, 有人可以帮我吗?
答案 0 :(得分:0)
我很傻,这是JSONObject和JSONArray 下面的代码将起作用:
JSONArray b = new JSONArray();
JSONObject a = new JSONObject();
b.put("5~CCCAGG~BTC~USD", "5~CCCAGG~ETH~USD", "11~BTC", "11~ETH")
a.put(b)
socket.emit("subs",a)