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();