中国地面气象站逐小时API Java国家气象信息中心API
public static void main(String[] args) throws IOException {List<String> num = new ArrayList<>();
String filePath = "src/main/resources/China_SURF_Station.xlsx";
File file = new File(filePath);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(file));
int tabIndex =0;
Sheet sheet = xssfWorkbook.getSheetAt(tabIndex);
Row row;
Cell cell1;
for (int i=0;i<sheet.getLastRowNum();i++){
row = sheet.getRow(i+1);
cell1 = row.getCell(0);
cell1.setCellType(CellType.STRING);
String cellValue0 = cell1.getStringCellValue();
num.add(cellValue0);
}
System.out.println(num);
String STATION_IdS=StringUtils.join(Arrays.asList(num.stream().limit(30).toArray()),",");
System.out.println(STATION_IdS);
String request = "http://api.data.cma.cn:8090/api?userId=****&pwd=***&dataFormat=json&interfaceId=getSurfEleByTimeRangeAndStaID&dataCode=SURF_CHN_MUL_HOR&timeRange=&staIDs="+STATION_IdS+"&elements=Station_Id_C,Year,Mon,Day,Hour,PRS,PRS_Sea,PRS_Max,PRS_Min,RHU,RHU_Min,VAP,PRE_1h,TEM,TEM_Max,TEM_Min,&dataCode=SURF_CHN_MUL_HOR";
URL url = new URL(request);
StringBuilder document = new StringBuilder();
URLConnection conn = url.openConnection();//URL请求
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));//获取数据流
String line = null;
while ((line = reader.readLine()) != null) {
document.append(line);
}
reader.close();
JSONObject json = JSONObject.parseObject(document.toString());
System.out.println(json);
}国家气象信息中心-中国气象数据网 (cma.cn) 66666666666
页:
[1]