summaryrefslogtreecommitdiff
path: root/src/JSONReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/JSONReader.java')
-rw-r--r--src/JSONReader.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/JSONReader.java b/src/JSONReader.java
index a4af8c9..4cc72ad 100644
--- a/src/JSONReader.java
+++ b/src/JSONReader.java
@@ -12,9 +12,10 @@ import java.io.*;
* https://stackoverflow.com/questions/3880274/how-to-convert-the-object-to-string-in-java
* https://stackoverflow.com/questions/8938498/get-the-index-of-a-pattern-in-a-string-using-regex
* https://howtodoinjava.com/java/regex/start-end-of-string/
+ * https://www.baeldung.com/java-remove-last-character-of-string
*
* Date:
- * 2024-05-20
+ * 2024-05-25
*
* Purpose of class:
* Read from and interpret JSON files.
@@ -77,9 +78,15 @@ public class JSONReader extends Reader {
/* This JSON is pretty-printed. */
int nl = json.indexOf("\n", start);
- /* Extract substring. Remove any quotation marks and commas. */
- String substring = json.substring(start, nl);
- return substring.replaceAll("[\",]", "");
+ /* Extract substring. Remove any quotation marks. */
+ String extract = json.substring(start, nl);
+ extract = extract.replaceAll("\"", "");
+
+ /* If the string ends with a comma, remove it. */
+ if (extract.endsWith(",")) {
+ extract = extract.substring(0, extract.length() - 1);
+ }
+ return extract;
}
/**