-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
49 lines (40 loc) · 1.21 KB
/
Parser.java
File metadata and controls
49 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package goEuro;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class Parser {
InputStreamReader data;
List<Airport> results;
Parser(InputStreamReader data)
{
this.data = data;
this.results = new ArrayList<Airport>();
}
public void doParse() throws NullPointerException
{
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(this.data);
JsonArray rootobj = root.getAsJsonArray();
Iterator<JsonElement> itr = rootobj.iterator();
while(itr.hasNext())
{
Airport ap = new Airport();
JsonObject jobj = itr.next().getAsJsonObject();
JsonObject pos = jobj.get("geo_position").getAsJsonObject();
ap._id = jobj.get("_id").getAsInt();
ap.name = jobj.get("name").getAsString();
ap.type = jobj.get("type").getAsString();
ap.latitude = pos.get("latitude").getAsDouble();
ap.longitude = pos.get("longitude").getAsDouble();
results.add(ap);
}
}
public List<Airport> getResults(){
return this.results;
}
}