@@ -37,8 +45,8 @@ public record Difficulty( @Nonnull public String toStringSimple () { return String.format( - "\"difficulty\":%d,\"notes\":%d", - level, noteCount + "\"id\":%s,\"difficulty\":%d,\"notes\":%d", + Converter.parseJSONString(id), level, noteCount ); } diff --git a/src/main/java/cc/sukazyo/sekai_scores/Song.java b/src/main/java/cc/sukazyo/sekai_scores/Song.java index 744051f..791f6a1 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/Song.java +++ b/src/main/java/cc/sukazyo/sekai_scores/Song.java @@ -5,6 +5,7 @@ import cc.sukazyo.sekai_scores.util.Converter; import javax.annotation.Nonnull; public record Song( + int id, @Nonnull String name, @Nonnull SongUnit unit, @Nonnull Difficulties difficulties @@ -14,7 +15,8 @@ public record Song( @Nonnull public String toString () { return String.format( - "{\"name\":\"%s\",\"unit\":%s,\"difficulties\":%s}", + "{\"id\":%d,\"name\":%s,\"unit\":%s,\"difficulties\":%s}", + id, Converter.parseJSONString(name), unit, difficulties diff --git a/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java b/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java index 756d9f0..6e588da 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java +++ b/src/main/java/cc/sukazyo/sekai_scores/SongUnit.java @@ -55,7 +55,7 @@ public enum SongUnit { @Nonnull public String toString() { return String.format( - "{\"id\":%d,\"fullname\":\"%s\"}", + "{\"id\":%d,\"fullname\":%s}", id, Converter.parseJSONString(name) ); diff --git a/src/main/java/cc/sukazyo/sekai_scores/util/Converter.java b/src/main/java/cc/sukazyo/sekai_scores/util/Converter.java index aa22aff..1309a9c 100644 --- a/src/main/java/cc/sukazyo/sekai_scores/util/Converter.java +++ b/src/main/java/cc/sukazyo/sekai_scores/util/Converter.java @@ -1,12 +1,14 @@ package cc.sukazyo.sekai_scores.util; import javax.annotation.Nonnull; +import javax.annotation.Nullable; public class Converter { @Nonnull - public static String parseJSONString (@Nonnull String input) { - return input.replaceAll("'", "\\'").replaceAll("\"", "\\\""); + public static String parseJSONString (@Nullable String input) { + if (input == null) return "null"; + return "\"" + input.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"") + "\""; } }