json连接中央气象台api异常
16lz
2021-01-23
//本来准备通过查找城市id后再通过id查找天气信息免去建立数据库的麻烦,但是api不稳定,只能通过建立id数据库来对应查找了
super.onCreate(savedInstanceState);String str = "http://toy.weather.com.cn/SearchBox/searchBox?"+ "callback=jsonp1342857491709&_=1342857620727&language=zh&keyword=guilin";try {URL url = new URL(str);HttpURLConnection cn = (HttpURLConnection) url.openConnection();cn.setConnectTimeout(5 * 1000);cn.setRequestMethod("GET");System.out.println("stream=======" + cn.getInputStream());InputStreamReader in = new InputStreamReader(cn.getInputStream());System.out.println("in======" + in);BufferedReader bu = new BufferedReader(in);String line = bu.readLine().toString();System.out.println("ling=====" + line);} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (ProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}
更多相关文章
- Android数据库SQLite使用详解一 : SQLiteOpenHelper详解
- android sqlite数据库封装 实现crud
- 在 Android 应用中使用数据库
- Android Sqlite数据库跨版本升级 保存之前数据
- Android中SQLite数据库介绍
- 【android】listview动态更新(与数据库之间的交道)
- Android系统源码数据库(mmssms.db)(转)