Advertisement
MarMar_IV

Untitled

Jan 31st, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.  
  2.     public static URL getUrlForPage(String pageAdress){
  3.         try {
  4.             return new URL(pageAdress);
  5.         } catch (MalformedURLException e) {
  6.             e.printStackTrace();
  7.         }
  8.  
  9.         return null;
  10.     }
  11.  
  12.     public static String downloadPageToString(URL url){
  13.         String res = "";
  14.         InputStream is;
  15.         BufferedReader br;
  16.         try {
  17.             is = url.openStream();
  18.             if(is != null){
  19.                 br = new BufferedReader(new InputStreamReader(is));
  20.  
  21.                 String line;
  22.                 while ((line = br.readLine()) != null) {
  23.                     res += line;
  24.                 }
  25.  
  26.                 return res;
  27.             }
  28.         } catch (IOException e) {
  29.             e.printStackTrace();
  30.         }
  31.  
  32.         return "";
  33.     }
  34.  
  35.     private static ArrayList<Integer> loadDoctorInInstitutionJSON(String json){
  36.         ArrayList<Integer> res = new ArrayList<>();
  37.  
  38.         JSONArray ja = null;
  39.         try {
  40.             ja = new JSONArray(json);
  41.             for(int i=0;i<ja.length();i++){
  42.                 JSONObject jo = ja.getJSONObject(i);
  43.  
  44.                 res.add(jo.getInt("DoctorID"));
  45.             }
  46.         } catch (JSONException e) {
  47.             e.printStackTrace();
  48.         }
  49.  
  50.         return res;
  51.     }
  52.    
  53.    
  54.    
  55.    
  56.     loadDoctorInInstitutionJSON(downloadPageToString(getUrlForPage("adresa_stranky.php")));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement