修复了json获取格式错误的问题
This commit is contained in:
@@ -54,8 +54,8 @@ public class PushDailyController {
|
|||||||
param1.setCity(DailyLoveConfigure.City_ID);
|
param1.setCity(DailyLoveConfigure.City_ID);
|
||||||
param1.setType("7");
|
param1.setType("7");
|
||||||
String weatherResp = dataRemoteClient.getWeather(param1);
|
String weatherResp = dataRemoteClient.getWeather(param1);
|
||||||
JsonNode weatherJson = mapper.readTree(weatherResp).get("result").get(0).get("list").get(1);
|
JsonNode weatherJson = mapper.readTree(weatherResp).get("result").get("list").get(1);
|
||||||
String city = mapper.readTree(weatherResp).get("result").get(0).get("area").asString();
|
String city = mapper.readTree(weatherResp).get("result").get("area").asString();
|
||||||
// JSONObject weatherJson1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(1);
|
// JSONObject weatherJson1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(1);
|
||||||
// String city1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getString("area");
|
// String city1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).getString("area");
|
||||||
Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
||||||
@@ -63,8 +63,8 @@ public class PushDailyController {
|
|||||||
resultVo.setAttribute("tomorrow", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_tomorrow));
|
resultVo.setAttribute("tomorrow", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_tomorrow));
|
||||||
resultVo.setAttribute("city", new DataItem(city, DailyLoveConfigure.Color_city));
|
resultVo.setAttribute("city", new DataItem(city, DailyLoveConfigure.Color_city));
|
||||||
resultVo.setAttribute("weather", new DataItem(weather.getWeather(), DailyLoveConfigure.Color_weather));
|
resultVo.setAttribute("weather", new DataItem(weather.getWeather(), DailyLoveConfigure.Color_weather));
|
||||||
resultVo.setAttribute("min_temperature", new DataItem(weather.getLowest(), DailyLoveConfigure.Color_minTem));
|
resultVo.setAttribute("min_temperature", new DataItem(weather.getLowest()+"℃", DailyLoveConfigure.Color_minTem));
|
||||||
resultVo.setAttribute("max_temperature", new DataItem(weather.getHighest(), DailyLoveConfigure.Color_maxTem));
|
resultVo.setAttribute("max_temperature", new DataItem(weather.getHighest()+"℃", DailyLoveConfigure.Color_maxTem));
|
||||||
resultVo.setAttribute("quality", new DataItem(weather.getVis(), DailyLoveConfigure.Color_quality));
|
resultVo.setAttribute("quality", new DataItem(weather.getVis(), DailyLoveConfigure.Color_quality));
|
||||||
|
|
||||||
|
|
||||||
@@ -72,17 +72,17 @@ public class PushDailyController {
|
|||||||
param2.setKey(DailyLoveConfigure.TianXin_Key);
|
param2.setKey(DailyLoveConfigure.TianXin_Key);
|
||||||
|
|
||||||
String tipsResp = dataRemoteClient.getTips(param2);
|
String tipsResp = dataRemoteClient.getTips(param2);
|
||||||
String tips = mapper.readTree(tipsResp).get("result").get(0).get("content").asString();
|
String tips = mapper.readTree(tipsResp).get("result").get("content").asString();
|
||||||
// String tips1 = JSONObject.parseObject(tipsResp).getJSONArray("result").getJSONObject(0).getString("content");
|
// String tips1 = JSONObject.parseObject(tipsResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||||
resultVo.setAttribute("tips", new DataItem(tips, DailyLoveConfigure.Color_tips));
|
resultVo.setAttribute("tips", new DataItem(tips, DailyLoveConfigure.Color_tips));
|
||||||
|
|
||||||
String nightResp = dataRemoteClient.getNight(param2);
|
String nightResp = dataRemoteClient.getNight(param2);
|
||||||
String night = mapper.readTree(nightResp).get("result").get(0).get("content").asString();
|
String night = mapper.readTree(nightResp).get("result").get("content").asString();
|
||||||
// String night1 = JSONObject.parseObject(nightResp).getJSONArray("result").getJSONObject(0).getString("content");
|
// String night1 = JSONObject.parseObject(nightResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||||
resultVo.setAttribute("night", new DataItem(night, DailyLoveConfigure.Color_night));
|
resultVo.setAttribute("night", new DataItem(night, DailyLoveConfigure.Color_night));
|
||||||
|
|
||||||
String rainbowResp = dataRemoteClient.getRainbow(param2);
|
String rainbowResp = dataRemoteClient.getRainbow(param2);
|
||||||
String rainbow = mapper.readTree(rainbowResp).get("result").get(0).get("content").asString();
|
String rainbow = mapper.readTree(rainbowResp).get("result").get("content").asString();
|
||||||
// String rainbow1 = JSONObject.parseObject(rainbowResp).getJSONArray("result").getJSONObject(0).getString("content");
|
// String rainbow1 = JSONObject.parseObject(rainbowResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||||
resultVo.setAttribute("rainbow", new DataItem(rainbow, DailyLoveConfigure.Color_dailyCn));
|
resultVo.setAttribute("rainbow", new DataItem(rainbow, DailyLoveConfigure.Color_dailyCn));
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ public class PushDailyController {
|
|||||||
param1.setCity(DailyLoveConfigure.City_ID);
|
param1.setCity(DailyLoveConfigure.City_ID);
|
||||||
param1.setType("1");
|
param1.setType("1");
|
||||||
String weatherResp = dataRemoteClient.getWeather(param1);
|
String weatherResp = dataRemoteClient.getWeather(param1);
|
||||||
JsonNode weatherJson = mapper.readTree(weatherResp).get("result").get(0);
|
JsonNode weatherJson = mapper.readTree(weatherResp).get("result");
|
||||||
Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
||||||
|
|
||||||
// Weather weather1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).toJavaObject(Weather.class);
|
// Weather weather1 = JSONObject.parseObject(weatherResp).getJSONArray("result").getJSONObject(0).toJavaObject(Weather.class);
|
||||||
@@ -166,8 +166,8 @@ public class PushDailyController {
|
|||||||
resultVo.setAttribute("now", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_Now));
|
resultVo.setAttribute("now", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_Now));
|
||||||
resultVo.setAttribute("city", new DataItem(weather.getArea(), DailyLoveConfigure.Color_city));
|
resultVo.setAttribute("city", new DataItem(weather.getArea(), DailyLoveConfigure.Color_city));
|
||||||
resultVo.setAttribute("weather", new DataItem(weather.getWeather(), DailyLoveConfigure.Color_weather));
|
resultVo.setAttribute("weather", new DataItem(weather.getWeather(), DailyLoveConfigure.Color_weather));
|
||||||
resultVo.setAttribute("min_temperature", new DataItem(weather.getLowest(), DailyLoveConfigure.Color_minTem));
|
resultVo.setAttribute("min_temperature", new DataItem(weather.getLowest()+"℃", DailyLoveConfigure.Color_minTem));
|
||||||
resultVo.setAttribute("max_temperature", new DataItem(weather.getHighest(), DailyLoveConfigure.Color_maxTem));
|
resultVo.setAttribute("max_temperature", new DataItem(weather.getHighest()+"℃", DailyLoveConfigure.Color_maxTem));
|
||||||
resultVo.setAttribute("quality", new DataItem(weather.getQuality(), DailyLoveConfigure.Color_quality));
|
resultVo.setAttribute("quality", new DataItem(weather.getQuality(), DailyLoveConfigure.Color_quality));
|
||||||
|
|
||||||
|
|
||||||
@@ -179,12 +179,12 @@ public class PushDailyController {
|
|||||||
// resultVo.setAttribute("tips", new DataItem(tips, DailyLoveConfigure.Color_tips));
|
// resultVo.setAttribute("tips", new DataItem(tips, DailyLoveConfigure.Color_tips));
|
||||||
|
|
||||||
String morningResp = dataRemoteClient.getMorning(param2);
|
String morningResp = dataRemoteClient.getMorning(param2);
|
||||||
String morning = mapper.readTree(morningResp).get("result").get(0).get("content").asString();
|
String morning = mapper.readTree(morningResp).get("result").get("content").asString();
|
||||||
// String morning1 = JSONObject.parseObject(morningResp).getJSONArray("result").getJSONObject(0).getString("content");
|
// String morning1 = JSONObject.parseObject(morningResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||||
resultVo.setAttribute("morning", new DataItem(morning, DailyLoveConfigure.Color_morning));
|
resultVo.setAttribute("morning", new DataItem(morning, DailyLoveConfigure.Color_morning));
|
||||||
|
|
||||||
String rainbowResp = dataRemoteClient.getRainbow(param2);
|
String rainbowResp = dataRemoteClient.getRainbow(param2);
|
||||||
String rainbow = mapper.readTree(rainbowResp).get("result").get(0).get("content").asString();
|
String rainbow = mapper.readTree(rainbowResp).get("result").get("content").asString();
|
||||||
// String rainbow1 = JSONObject.parseObject(rainbowResp).getJSONArray("result").getJSONObject(0).getString("content");
|
// String rainbow1 = JSONObject.parseObject(rainbowResp).getJSONArray("result").getJSONObject(0).getString("content");
|
||||||
resultVo.setAttribute("rainbow", new DataItem(rainbow, DailyLoveConfigure.Color_dailyCn));
|
resultVo.setAttribute("rainbow", new DataItem(rainbow, DailyLoveConfigure.Color_dailyCn));
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
package com.bamanker.dailylove;
|
package com.bamanker.dailylove;
|
||||||
|
|
||||||
|
import com.bamanker.dailylove.config.DailyLoveConfigure;
|
||||||
|
import com.bamanker.dailylove.domain.DataItem;
|
||||||
|
import com.bamanker.dailylove.domain.TianXinReqParam;
|
||||||
|
import com.bamanker.dailylove.domain.Weather;
|
||||||
|
import com.bamanker.dailylove.service.DataRemoteClient;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import tools.jackson.databind.JsonNode;
|
||||||
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import com.bamanker.dailylove.domain.*;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -10,6 +21,10 @@ class DailyLoveApplicationTests {
|
|||||||
// @Resource
|
// @Resource
|
||||||
// DataRemoteClient dataRemoteClient;
|
// DataRemoteClient dataRemoteClient;
|
||||||
//
|
//
|
||||||
|
// @Autowired
|
||||||
|
// ObjectMapper mapper;
|
||||||
|
|
||||||
|
//
|
||||||
// String remark = "❤";
|
// String remark = "❤";
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
@@ -88,24 +103,61 @@ class DailyLoveApplicationTests {
|
|||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
// void test2() {
|
// void test2() {
|
||||||
|
|
||||||
|
// ResultVo resultVo = ResultVo.initializeResultVo(DailyLoveConfigure.Open_ID,
|
||||||
|
// DailyLoveConfigure.Template_ID_Night,
|
||||||
|
// DailyLoveConfigure.Color_Top);
|
||||||
//
|
//
|
||||||
// TianXinReqParam param1 = new TianXinReqParam();
|
// TianXinReqParam param1 = new TianXinReqParam();
|
||||||
// param1.setKey(DailyLoveConfigure.TianXin_Key);
|
// param1.setKey(DailyLoveConfigure.TianXin_Key);
|
||||||
// param1.setCity(DailyLoveConfigure.City_ID);
|
// param1.setCity(DailyLoveConfigure.City_ID);
|
||||||
// param1.setType("7");
|
// param1.setType("7");
|
||||||
// String weatherJson = dataRemoteClient.getWeather(param1);
|
// String weatherResp = dataRemoteClient.getWeather(param1);
|
||||||
// log.info("weather:{}", weatherJson);
|
//// log.info("weather:{}", weatherResp);
|
||||||
// JSONObject resWeather = JSONObject.parseObject(weatherJson);
|
// JsonNode weatherJson = mapper.readTree(weatherResp).get("result").get("list").get(1);
|
||||||
// JSONObject result = resWeather.getJSONArray("result").getJSONObject(0).getJSONArray("list").getJSONObject(2);
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(weatherJson);
|
||||||
|
// String city = mapper.readTree(weatherResp).get("result").get("area").asString();
|
||||||
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(city);
|
||||||
|
// Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
||||||
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(weather);
|
||||||
|
//
|
||||||
|
// resultVo.setAttribute("tomorrow", new DataItem(weather.getDate() + " " + weather.getWeek(), DailyLoveConfigure.Color_tomorrow));
|
||||||
|
// resultVo.setAttribute("city", new DataItem(city, DailyLoveConfigure.Color_city));
|
||||||
|
// resultVo.setAttribute("weather", new DataItem(weather.getWeather(), DailyLoveConfigure.Color_weather));
|
||||||
|
// resultVo.setAttribute("min_temperature", new DataItem(weather.getLowest(), DailyLoveConfigure.Color_minTem));
|
||||||
|
// resultVo.setAttribute("max_temperature", new DataItem(weather.getHighest(), DailyLoveConfigure.Color_maxTem));
|
||||||
|
// resultVo.setAttribute("quality", new DataItem(weather.getVis(), DailyLoveConfigure.Color_quality));
|
||||||
|
//
|
||||||
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(resultVo);
|
||||||
|
|
||||||
|
// TianXinReqParam param2 = new TianXinReqParam();
|
||||||
|
// param2.setKey(DailyLoveConfigure.TianXin_Key);
|
||||||
|
//
|
||||||
|
// String tipsResp = dataRemoteClient.getTips(param2);
|
||||||
|
// String tips = mapper.readTree(tipsResp).get("result").get("content").asString();
|
||||||
|
//
|
||||||
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(tips);
|
||||||
|
//
|
||||||
|
// TianXinReqParam param1 = new TianXinReqParam();
|
||||||
|
// param1.setKey(DailyLoveConfigure.TianXin_Key);
|
||||||
|
// param1.setCity(DailyLoveConfigure.City_ID);
|
||||||
|
// param1.setType("1");
|
||||||
|
// String weatherResp = dataRemoteClient.getWeather(param1);
|
||||||
|
// JsonNode weatherJson = mapper.readTree(weatherResp).get("result");
|
||||||
|
// Weather weather = mapper.treeToValue(weatherJson, Weather.class);
|
||||||
|
//
|
||||||
|
// System.out.println("-----------------------------");
|
||||||
|
// System.out.println(weather);
|
||||||
|
|
||||||
// log.info("----result----:{}", result);
|
// log.info("----result----:{}", result);
|
||||||
// Weather weather = result.toJavaObject(Weather.class);
|
|
||||||
// log.info("weather:{}", weather);
|
|
||||||
// ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate(weather.getDate()));
|
//}
|
||||||
// System.out.println("--------------55555----------"+weather.getDate());
|
|
||||||
// System.out.println("------------------------"+chineseDate);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
|
|||||||
Reference in New Issue
Block a user