Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upJsonReader fails to read string with escaped Backslashes #2370
Comments
|
JSON uses backslash for escaping. static public class Test {
public String value;
}
public static void main (String[] args) throws Exception {
String[] tests = {"meow\\meow", "meow \\ ", "meow \\ ", "meow \\\"meow\\\""};
for (String s : tests) {
Test test = new Test();
test.value = s;
System.out.println(test.value);
String json = new Json().toJson(test);
System.out.println(json);
Test test2 = new Json().fromJson(Test.class, json);
System.out.println(test2.value);
if (!test2.value.equals(test.value)) throw new RuntimeException(s);
System.out.println();
}
} |
|
I think there is a difference between your answer and my question. You are generating an object using Json and I am using the JsonParser. For example, how would you create (clear text) [he\she\it] with JsonReader?
|
|
these String literals except works01 don't compile |
|
I used Edit: this is even worse because to get these examples to show up correctly in GitHub's markdown, I had to escape all the slashes! This is probably why @dermetfan reported that your example doesn't compile. This thread is backslash hell! I don't think there is any actual problem here though. |
|
thanks made it clear |

As I updated the project today I wondered about a json-parsing error.
Using 1.3.2-Snapshot (23.08.2014).
fail0 worked in 1.2.0, (maybe in some 1.3.2 version but I am not sure)
fails1 throws: Illegal escaped character: \
fails2 throws: Error parsing JSON, unmatched brace.
Cheers