| | |
| | | try { |
| | | Map<String, Object> map = gson.fromJson(message, new TypeToken<Map<String, Object>>() {}.getType()); |
| | | |
| | | |
| | | if (map != null && map.containsKey("s")) { |
| | | |
| | | Object object = map.get("d"); |
| | | Map<String, Object> resultMap = gson.fromJson(object.toString(), new TypeToken<Map<String, Object>>() {}.getType()); |
| | | HashMap<String,Object> hashMap = new HashMap<>(); |
| | |
| | | List<Map<String,Object>> asksList = gson.fromJson(asksObj.toString(), listType); |
| | | List<Map<String,Object>> bidsList = gson.fromJson(bidsObj.toString(), listType); |
| | | |
| | | if (!asksList.isEmpty()) { |
| | | |
| | | if(!asksList.isEmpty() && !asksList.get(0).isEmpty() && !bidsList.isEmpty() && !bidsList.get(0).isEmpty()){ |
| | | if (!asksList.isEmpty() && !asksList.get(0).isEmpty()) { |
| | | |
| | | Map<String,Object> objectMap = asksList.get(0); |
| | | HashMap<String, Object> pvMap = new HashMap<>(); // 创建新的 HashMap 保存 bids 和 asks |
| | | pvMap.put("p", new BigDecimal(objectMap.get("p").toString())); |
| | | pvMap.put("v", new BigDecimal(objectMap.get("v").toString())); |
| | | pvMap.put("p", new BigDecimal(objectMap.get("p").toString()).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(objectMap.get("v").toString()).toPlainString()); |
| | | hashMap.put("asks", pvMap); |
| | | } |
| | | |
| | | if (!bidsList.isEmpty()) { |
| | | if (!bidsList.isEmpty() && !bidsList.get(0).isEmpty()) { |
| | | Map<String,Object> objectMap = bidsList.get(0); |
| | | HashMap<String, Object> pvMap = new HashMap<>(); // 创建新的 HashMap 保存 bids 和 asks |
| | | pvMap.put("p", new BigDecimal(objectMap.get("p").toString())); |
| | | pvMap.put("v", new BigDecimal(objectMap.get("v").toString())); |
| | | pvMap.put("p", new BigDecimal(objectMap.get("p").toString()).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(objectMap.get("v").toString()).toPlainString()); |
| | | hashMap.put("bids", pvMap); |
| | | } |
| | | |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } catch (JsonSyntaxException e) { |
| | | log.error("JSON 解析异常:" + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | |
| | | @OnClose |
| | | public void onClose() { |