`

JSON解析

 
阅读更多

json为字符串

 

String path = "http://www.secn.com.cn?format=json";
  URL url = new URL(path);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setReadTimeout(5*1000);
  conn.setRequestMethod("GET");
  InputStream inStream = conn.getInputStream();
  byte[] data = readerInStream(inStream);
  String json = new String(data);

 

JSONArray array = new JSONArray(json);
  for(int i=0; i< array.length(); i++){
   JSONObject item = array.getJSONObject(i);
   int id = item.getInt("id");
   String title = item.getString("title");
  }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics