如何将网站的结果(例如https://blockchain.info/de/q/24hrprice)转换为字符串/整数?我必须从网站上阅读源代码吗?从网站到字符串的结果
我正在开发Android Studio。
如何将网站的结果(例如https://blockchain.info/de/q/24hrprice)转换为字符串/整数?我必须从网站上阅读源代码吗?从网站到字符串的结果
我正在开发Android Studio。
BufferedReader in = null;
try {
String urlStr = "https://blockchain.info/de/q/24hrprice";
URL url = new URL(urlStr);
URLConnection con = url.openConnection();
in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String input;
while ((input = in.readLine()) != null) {
System.out.println(input); //you can parse input as Integer or Double now
}
} catch (MalformedURLException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
} finally {
try {
in.close();
} catch (Exception ex) {
System.err.println(ex);
}
}
感谢您的快速响应!当我尝试使用您的代码时,出现以下错误: 新的URL(urlStr)错误:java.net.malformedurlexception url.openConnection,con.getInputStream,in.readLine和in.close错误:java.io. IOException 我在做什么错? – user3254327 2014-11-05 11:57:18
我不知道...它适用于我。你有没有复制我更新的答案?我只是更改了urlStr,以包含“https://”,而我并没有在第一个版本中使用它。 – vefthym 2014-11-05 12:00:50
等等...你把它放在try-catch块吗? – vefthym 2014-11-05 12:02:05
结果是什么? – vefthym 2014-11-05 10:46:14
https://blockchain.info/de/q/24hrprice(=〜337.5)的结果。 – user3254327 2014-11-05 10:46:50