Add getjson
This commit is contained in:
parent
7007787848
commit
899a118769
@ -4,6 +4,16 @@ import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//Informieren Sie sich über die bereitgestellten Links (oder eigene Recherche) zu folgenden Themen:
|
||||
//JSON
|
||||
//URL-Abruf mit Java
|
||||
//JSON-Verarbeitung mit Java
|
||||
//Dateiverarbeitung mit Java
|
||||
//Suchen Sie sich von der Seite http://deutschland.maps.sensor.community/ einen Sensor aus
|
||||
//Rufen Sie alle 2,5 Minuten mit Java die Sensordaten "ihres" Sensors ab
|
||||
//Speichern Sie nur die aktuelle Messung aus der Abfrage in einer Datei mit dem Namen <Land>-<SensorID>-<timestamp>.json
|
||||
//Wählen Sie einen objektorientierten Ansatz für die Umsetzung.
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException, ParseException {
|
||||
APIPaser api = new APIPaser("https://data.sensor.community/airrohr/v1/sensor/35943/");
|
||||
|
@ -2,7 +2,11 @@ package sh.adb.sensorCommunityAPI;
|
||||
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -14,9 +18,26 @@ public class dataStore {
|
||||
try {
|
||||
file.write(json.toJSONString());
|
||||
check = true;
|
||||
|
||||
}catch (IOException e){
|
||||
System.out.println("Sorry cant write in file" + path);
|
||||
System.out.println("Can not write in file: " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return check;
|
||||
}
|
||||
}
|
||||
public JSONObject getjson(String path) throws IOException, ParseException {
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject jsonObject = null;
|
||||
|
||||
try {
|
||||
Object obj = parser.parse(new FileReader(path));
|
||||
jsonObject = (JSONObject) obj;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Can not create Jsonobjekt from path: " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user