Ah, nice workaround.
Though I wasn't actually having problems with embedding '#' in json Strings, rather I was having problems using the included json.jar API to parse Starsector's data files.
I was passing the json straight to the loader, without 1st stripping the comments (as your LoadingUtils class does).
While investigating the cause, I spotted the above mentioned '#' limitation.
Rather than duplicating your 2-stage parsing, I just
patched overrode JSONTokenizer.nextClean() thus:
(disclaimer: I've not yet exhaustively tested it; there might be places where placing a '#' still causes a failure)
package org.tjj.starsector.ssme;
import java.io.Reader;
import org.json.JSONException;
import org.json.JSONTokener;
/**
* Fixes the json tokenizer so it respects '#' comments,
* so you don't need to strip them out of Starsector's data files before parsing them.
*
* @author TehJumpingJawa
*
*/
public class ImprovedJSONTokener extends JSONTokener {
public ImprovedJSONTokener(Reader arg0) {
super(arg0);
}
public ImprovedJSONTokener(String arg0) {
super(arg0);
}
public char nextClean() throws JSONException {
boolean inComment = false;
for (;;) {
char c = this.next();
if (c == 0) {
// eof
return c;
} else {
if (inComment) {
if (c == '\n') {
inComment = false;
}
} else {
if (c == '#') {
inComment = true;
} else if (c > ' ') {
return c;
}
}
}
}
}
}