Created
June 16, 2012 06:37
-
-
Save laabroo/2940223 to your computer and use it in GitHub Desktop.
Parsing Json From String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void getAll(double lat, double lon, double rad) { | |
String posisis = loadData(lat, lon, rad); | |
Log.i("Posisi : ", posisis); | |
try { | |
JSONObject obj = new JSONObject(posisis); | |
JSONArray jsonArray = obj.getJSONArray("items"); | |
for (int i = 0; i < jsonArray.length(); i++) { | |
JSONObject jsonObject = jsonArray.getJSONObject(i); | |
String name = jsonObject.getString("name"); | |
String latitude = jsonObject.getString("latitude"); | |
String longitude = jsonObject.getString("longitude"); | |
String address = jsonObject.getString("address"); | |
String radius = jsonObject.getString("distance"); | |
Log.i("Data Hasil : ", name + "," + latitude + "," + longitude | |
+ ", " + radius); | |
lat = new Double(latitude); | |
lon = new Double(longitude); | |
rad = new Double(radius); | |
place = new Place(); | |
place.setAddress(address); | |
place.setLat(Double.valueOf(latitude)); | |
place.setLon(Double.valueOf(longitude)); | |
place.setName(name); | |
place.setRad(Double.valueOf(radius)); | |
Log.i("Place : ", place.toString()); | |
list_lokasi.add(place); | |
} | |
} | |
catch (ClassCastException e) { | |
e.printStackTrace(); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parsing Json dari data String yang di dapat dari balikan method loadData. Karna data yang diterima dalam bentuk format JSON maka di parsing berdasarkan nama object yang akan di ambil misalnya di sini objectnya yaitu name, latitude, longitude, address, radius. Setelah didapat semua data yang di inginkan maka di object-object yang didapat itu di masukan dalam Object Place dan di masukan lagi kedalam list agagr bisa ditampilkan.