Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package com.example.harm.blindwallgallery;
  2.  
  3. import org.json.JSONArray;
  4. import org.json.JSONObject;
  5.  
  6. /**
  7. * Created by harm on 20-2-2018.
  8. */
  9.  
  10. public class BlindwallAsyncTask {
  11. JSONArray blindWalls;
  12.  
  13. try {
  14. URL url = new URL(blindwallUrl);
  15.  
  16. URLConnection urlConnection = url.openConnection();
  17.  
  18. if(!(urlConnection instanceof HttpURLConnection)) {
  19. return null;
  20. }
  21.  
  22. HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  23. httpConnection.setAllowUserInteraction(false);
  24. httpConnection.setInstanceFollowRedirects(true);
  25. httpConnection.setRequestMethod("GET");
  26.  
  27. httpConnection.connect();
  28.  
  29. responseCode = httpConnection.getResponseCode();
  30. if (responseCode == HttpURLConnection.HTTP_OK) {
  31. inputStream = httpConnection.getInputStream();
  32. response = getStringFromInputStream(inputStream);
  33. // Log.i(TAG, "doInBackground response = " + response);
  34. } else {
  35. Log.e(TAG, "Error, invalid response");
  36. }
  37. if (response != null) try {
  38. inputStream.close();
  39. } catch (IOException logOrIgnore) {
  40.  
  41. }
  42.  
  43. } catch (MalformedURLException e) {
  44. Log.e(TAG, "doInBackground MalformedURLEx " + e.getLocalizedMessage());
  45. return null;
  46. } catch (IOException e) {
  47. Log.e("TAG", "doInBackground IOException " + e.getLocalizedMessage());
  48. return null;
  49. }
  50. return response;
  51.  
  52. try {
  53. blindWalls = new JSONArray(response);
  54.  
  55. for(int idx = 0; idx < blindWalls.length(); idx++) {
  56. JSONObject blindWall = blindWalls.getJSONObject(idx);
  57.  
  58. JSONObject material = blindWall.getJSONObject("material");
  59. String materialString = material.getString("nl");
  60.  
  61. JSONObject description = blindWall.getJSONObject("description");
  62. String descriptionString = description.getString("nl");
  63.  
  64. JSONObject title = blindWall.getJSONObject("title");
  65. String titleString = title.getString("nl");
  66.  
  67. JSONArray imageArray = blindWall.getJSONArray("images");
  68. JSONObject imageObject = imageArray.getJSONObject(0);
  69. String imageString = imageObject.getString("url");
  70.  
  71. imageString = "https://api.blindwalls.gallery/" + imageString;
  72.  
  73. String photographer = blindWall.getString("photographer");
  74.  
  75. String address = blindWall.getString("address");
  76.  
  77. int addressNumber = blindWall.getInt("numberOnMap");
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement