public volatile boolean parsingComplete = true;
public ArrayList<Item_DTO> obj = new ArrayList<Item_DTO>();
public HandleJSON(String url) {
this.urlString = url;
}
/*public String getTitle() {
return title;
}
public String getLongitude() {
return longitude;
}
public String getLatitude() {
return latitude;
}
*/
@SuppressLint("NewApi")
public void readAndParseJSON(String in) {
try {
JSONObject reader = new JSONObject(in);
JSONArray js
lengthJs
// Toast.makeText(HandleJSON.this, "arry size : -"+lengthJsonArr, 5000).show();
for (int i = 0; i < lengthJsonArr; i++) {
System.out.println("array size :=======================================>>>" +lengthJsonArr);
/****** Get Object for each JSON node. ***********/
JSONObject js
Item_DTO nn = new Item_DTO();
JSONObject propertiesJs
.getJSONObject("properties");
/******* Fetch node values **********/
nn.setTitle(propertiesJsonObject.optString("title").toString());
System.out.println("title :" + nn.getTitle());
JSONObject geometryJs
.getJSONObject("geometry");
JSONArray coordinatesJs geometryJsonObject
.getJSONArray("coordinates");
if (coordinatesJsonArray.length() != 0) {
nn.setLongitude(coordinatesJsonArray.get(0).toString());
nn.setLatitude(coordinatesJsonArray.get(1).toString());
System.out.println("longitude :" + nn.getLongitude());
System.out.println("latitude :" + nn.getLatitude());
}
obj.add(nn);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
parsingComplete = false;
}
public void fetchJSON() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(urlString);
HttpURLConnection c url
.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
InputStream stream = conn.getInputStream();
String data = convertStreamToString(stream);
readAndParseJSON(data);
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
}Add a code snippet to your website: www.paste.org