From 2f8657157856112823af96683d7069dddca9e730 Mon Sep 17 00:00:00 2001 From: gs Date: Tue, 25 Jun 2024 18:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E9=97=AE=E9=A2=98=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/stock/market/web/BTodayStockController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/stock/market/web/BTodayStockController.java b/src/main/java/cn/stock/market/web/BTodayStockController.java index 34066cb..457a391 100644 --- a/src/main/java/cn/stock/market/web/BTodayStockController.java +++ b/src/main/java/cn/stock/market/web/BTodayStockController.java @@ -160,12 +160,14 @@ public class BTodayStockController { String forObject = restTemplate.getForObject(apiUrl, String.class); JSONObject jsonObject = JSON.parseObject(forObject); - String price = jsonObject.getString("price"); - if (price != null) { + JSONArray arryData = jsonObject.getJSONArray("data"); + if (arryData != null&&arryData.size()>0) { try { + JSONObject jsonObject1 = arryData.getJSONObject(0); + String price = jsonObject1.getString("price"); double priceValue = Double.parseDouble(price); DecimalFormat df = new DecimalFormat("0.00"); - jsonObject.put("price", df.format(priceValue)); + jsonObject1.put("price", df.format(priceValue)); } catch (NumberFormatException e) { // Handle the case where price is not a valid double e.printStackTrace();