Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.harm.blindwallgallery;
- import org.json.JSONArray;
- import org.json.JSONObject;
- /**
- * Created by harm on 20-2-2018.
- */
- public class BlindwallAsyncTask {
- JSONArray blindWalls;
- try {
- URL url = new URL(blindwallUrl);
- URLConnection urlConnection = url.openConnection();
- if(!(urlConnection instanceof HttpURLConnection)) {
- return null;
- }
- HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
- httpConnection.setAllowUserInteraction(false);
- httpConnection.setInstanceFollowRedirects(true);
- httpConnection.setRequestMethod("GET");
- httpConnection.connect();
- responseCode = httpConnection.getResponseCode();
- if (responseCode == HttpURLConnection.HTTP_OK) {
- inputStream = httpConnection.getInputStream();
- response = getStringFromInputStream(inputStream);
- // Log.i(TAG, "doInBackground response = " + response);
- } else {
- Log.e(TAG, "Error, invalid response");
- }
- if (response != null) try {
- inputStream.close();
- } catch (IOException logOrIgnore) {
- }
- } catch (MalformedURLException e) {
- Log.e(TAG, "doInBackground MalformedURLEx " + e.getLocalizedMessage());
- return null;
- } catch (IOException e) {
- Log.e("TAG", "doInBackground IOException " + e.getLocalizedMessage());
- return null;
- }
- return response;
- try {
- blindWalls = new JSONArray(response);
- for(int idx = 0; idx < blindWalls.length(); idx++) {
- JSONObject blindWall = blindWalls.getJSONObject(idx);
- JSONObject material = blindWall.getJSONObject("material");
- String materialString = material.getString("nl");
- JSONObject description = blindWall.getJSONObject("description");
- String descriptionString = description.getString("nl");
- JSONObject title = blindWall.getJSONObject("title");
- String titleString = title.getString("nl");
- JSONArray imageArray = blindWall.getJSONArray("images");
- JSONObject imageObject = imageArray.getJSONObject(0);
- String imageString = imageObject.getString("url");
- imageString = "https://api.blindwalls.gallery/" + imageString;
- String photographer = blindWall.getString("photographer");
- String address = blindWall.getString("address");
- int addressNumber = blindWall.getInt("numberOnMap");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement