I noticed that Gson converts the string "<" into an unicode escape sequence in JSON output. Can you avoid this somehow, or do characters like "<" and ">" always have to be escaped in JSON?
考虑这个打印{"s":"\u003c"}
的示例;我只需要{"s":"<"}
.
public static void main(String[] args) {
Gson gson = new GsonBuilder().create();
System.out.println(gson.toJson(new Foo()));
}
static class Foo {
String s = "<";
}
上下文:我正在创建的JSON与HTML页面甚至JavaScript无关;它只是用来将某些 struct 化信息传递给另一个软件(嵌入在设备中,用C编写).