我使用 json-simple 读取 JSON 文件,以更改其中的属性 并将它们写回到文件中。这是一行:
{"username": "M\u00e4nnlich2", "url": "http://www.dslr-forum.de/showthread.php?t=1303001"}
问题: 当我将它们加载到 JSONObject 时,我将其作为 Map 获取:
{"username": "Männlich2", "url":"http:\/\/www.dslr-forum.de\/showthread.php?t=1303001"}
我想保留编码“M\u00e4nnlich2”,并且网址不应转义。
这正常吗?当我将其解析为 JSONObject 时如何保留编码? 或者我应该使用不同的 JSON 库?
这里是一些示例代码:
BufferedReader bfr = new BufferedReader(
new InputStreamReader(
new FileInputStream("tt"), "UTF8"));
JSONParser parser=new JSONParser();
JSONObject root=(JSONObject)parser.parse(bfr);
String jsonText = root.toJSONString();
//Here the String has lost the encoding
最佳答案
这是绝对正确的。 JSON 一旦转换为内部表示就无法记住原始格式。没有图书馆会有所帮助。
实际上,这与 JSON 无关,只是这两个序列产生相同的字符串...
关于java - Java 中的 JSON : Using encoded JSON files and keeping it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33653443/