这篇文章将为大家详细讲解有关Android应用中如何解析获取的JSON数据,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。根据指定的URL从Google 服务器上获得包含地址的json格式的数
这篇文章将为大家详细讲解有关Android应用中如何解析获取的JSON数据,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
根据指定的URL从Google 服务器上获得包含地址的json格式的数据(其还提供xml格式的,但json解析效率比xml高)
private static StringBuffer getJSONData(String urlPath){ try { URL url = new URL(urlPath); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setReadTimeout(5000); httpURLConnection.setRequestMethod("GET"); if(httpURLConnection.getResponseCode() == 200){ InputStream inputStream = httpURLConnection.getInputStream(); InputStreamReader isr = new InputStreamReader(inputStream); BufferedReader br = new BufferedReader(isr); String temp = null; StringBuffer jsonsb = new StringBuffer(); while((temp = br.readLine()) != null){ jsonsb.append(temp); } return jsonsb; } } catch (MalfORMedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null;}
--结束END--
本文标题: Android应用中如何解析获取的json数据
本文链接: https://www.lsjlt.com/news/225158.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0