I am trying to make an app that uses jsonObject to parse earthquake info. like longitude and latitude and magnitude form http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson and display it in a text view. I dont have much knoweledge in JSON..I have seen some vedio tutorial in YOUTUBE but I am not being able to get what i want...Can some one please provide me with The code to do this.
Asked
Active
Viewed 1,375 times
2 Answers
1
You want a JSON parsing library. I would suggest you use jackson: http://jackson.codehaus.org/Download
Go to your url (http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson), and copy all the json into your clipboard, then paste it into http://jsonlint.com/ and click verify. This tool will help you see the structure of the json file.
Here is a tutorial using jackson http://www.journaldev.com/2324/jackson-json-processing-api-in-java-example-tutorial

benathon
- 7,455
- 2
- 41
- 70
-
i am very new to these things and i dont understand anything. :( Can u please provide me the code – AD1TYA Feb 08 '14 at 05:47
-
It's clear that you don't have the abilities to accomplish this task. Stack Overflow is not a place where we do your job for you. You need to research the very basics of android app development: http://www.creativebloq.com/app-design/how-build-app-tutorials-12121473. You should also study basic java – benathon Feb 09 '14 at 04:37
1
You can use Gson - https://code.google.com/p/google-gson/
import java.util.List;
public class Earthquake {
public String type;
public Metadata metadata;
public double[] bbox;
public List<Feature> features;
public class Metadata{
public long generated;
public String url, title, api;
public int status, count;
}
public class Feature {
public String type, id;
public Properties properties;
public class Properties{
public int mag, tz, felt, cdi, sig, gap;
public String place, url, detail, mmi, alert, status, tsunami, net, code, ids, sources, types, nst, magType, type, title;
public long time, updated;
public double dmin, rms;
}
public class Geometry{
public String type;
public double[] coordinates;
}
}
}
With this class made you can do:
String data = getData(); //Get your data as a string
Earthquake e = new Gson().fromJson(data, Earthquake.class);

snotyak
- 3,709
- 6
- 35
- 52
-
can u be more specific about the this part: String data = getData(); Earthquake e = new Gson().fromJson(data, Earthquake.class); – AD1TYA Feb 08 '14 at 06:07
-
-
1Gson will deserialize JSON data from a string. Your `data` object will be the json from the website you provided earlier. – snotyak Feb 08 '14 at 06:28