Added basic support for backslash escaping for json writer, parser implementation is incomplete

This commit is contained in:
Ziver Koc 2015-04-17 21:01:41 +00:00
parent 0bd94eeebf
commit ddaac6163a
2 changed files with 16 additions and 4 deletions

View file

@ -83,7 +83,7 @@ public class JSONWriter{
out.append(", ");
String key = it.next();
out.append('\"');
out.append(key);
out.append(escapeString(key));
out.append("\": ");
write(root.get(key));
first = false;
@ -104,7 +104,7 @@ public class JSONWriter{
default:
if(root.getString() != null && root.getType() == DataType.String){
out.append('\"');
out.append(root.toString());
out.append(escapeString(root.toString()));
out.append('\"');
} else
out.append(root.toString());
@ -112,6 +112,11 @@ public class JSONWriter{
}
}
private static String escapeString(String str){
// Replace one backslash with two
return str.replaceAll("\\\\", "\\\\\\\\");
}
/**
* Closes the internal stream
*/