Browse Source

Added writeObject method to the JSON Parser to write json objects

remotes/origin/quiz
Friederike von Gruben 2 years ago
parent
commit
ad42f3ff85
  1. 21
      src/main/java/org/bitbiome/classes/JsonParser.java

21
src/main/java/org/bitbiome/classes/JsonParser.java

@ -2,8 +2,14 @@ package org.bitbiome.classes;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
public class JsonParser {
@ -30,7 +36,20 @@ public class JsonParser {
}
JSONTokener tokener = new JSONTokener(is);
return new JSONObject(tokener);
}
public static void writeObject(String fileName, JSONObject object) {
String resourceName = System.getProperty("user.dir") + "/src/main/resources/" + fileName;
try {
FileWriter fw = new FileWriter(resourceName, false);
fw.write(object.toString(1));
fw.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading…
Cancel
Save