import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.*; public class pm { public static String loadJson (String url) { StringBuilder json = new StringBuilder(); try { URL urlObject = new URL(url); URLConnection uc = urlObject.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8")); String inputLine = null; while ( (inputLine = in.readLine()) != null) { json.append(inputLine); } in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return json.toString(); } public static void main(String[] args) { String url = "http://www.pm25.in/api/querys.json?token=5j1znBVAsnSf5xQyNQyq"; String json = loadJson(url); System.out.println(json); } }
获取一个城市所有监测点的PM2.5数据
地址 http://www.pm25.in/api/querys/pm2_5.json?city=weinan&token=5j1znBVAsnSf5xQyNQyq
详细过程可查看 http://www.cnblogs.com/sanzangtdashi/p/6807341.html
详细过程可查看 http://www.cnblogs.com/sanzangtdashi/p/6807341.html
详细过程可查看 http://www.cnblogs.com/sanzangtdashi/p/6807341.html
结果截图