新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android應(yīng)用中如何解析獲取的json數(shù)據(jù)-創(chuàng)新互聯(lián)
這篇文章將為大家詳細(xì)講解有關(guān)Android應(yīng)用中如何解析獲取的json數(shù)據(jù),文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
第一步:根據(jù)指定的URL從google 服務(wù)器上獲得包含地址的json格式的數(shù)據(jù)(其還提供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; }
本文題目:Android應(yīng)用中如何解析獲取的json數(shù)據(jù)-創(chuàng)新互聯(lián)
URL地址:http://www.ef60e0e.cn/article/copjeg.html