I'm trying to parse a json file using the org.json.simple library and I'm getting null pointer exception when I try to instantiate the iterator with the Map.
@SuppressWarnings("unchecked")
public static void main(String[] args) {
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("wadingpools.json"));
JSONObject jsonObject = (JSONObject) obj;
System.out.println(jsonObject);
JSONArray featuresArray = (JSONArray) jsonObject.get("features");
Iterator iter = featuresArray.iterator();
while (iter.hasNext()) {
Map<String, String> propertiesMap = ((Map<String, String>) jsonObject.get("properties"));
Iterator<Map.Entry<String, String>> itrMap = propertiesMap.entrySet().iterator();
while(itrMap.hasNext()){
Map.Entry<String, String> pair = itrMap.next();
System.out.println(pair.getKey() + " : " + pair.getValue());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Here is a snippet of part of the JSON file. I'm trying to get the NAME in the properties object.
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"properties": {
"PARK_ID": 393,
"FACILITYID": 26249,
"NAME": "Wading Pool - Crestview",
"NAME_FR": "Pataugeoire - Crestview",
"ADDRESS": "58 Fieldrow St."
},