Java中的JSON:使用编码的JSON文件并保存它
Im使用json simple从json文件中读取,以更改其中的属性 并将它们写回一个文件。这是一行:Java中的JSON:使用编码的JSON文件并保存它,java,json,file,encoding,json-simple,Java,Json,File,Encoding,Json Simple,Im使用json simple从json文件中读取,以更改其中的属性 并将它们写回一个文件。这是一行: {"username": "M\u00e4nnlich2", "url": "http://www.dslr-forum.de/showthread.php?t=1303001"} 问题: 当我将它们加载到JSONObject时,我将其作为映射: {"username": "Männlich2", "url":"http:\/\/www.dslr-forum.de\/showthread.p
{"username": "M\u00e4nnlich2", "url": "http://www.dslr-forum.de/showthread.php?t=1303001"}
问题:
当我将它们加载到JSONObject时,我将其作为映射:
{"username": "Männlich2", "url":"http:\/\/www.dslr-forum.de\/showthread.php?t=1303001"}
我想保留编码“M\u00e4nnlich2”,并且url不应得到转义
这正常吗?当我将其解析为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并没有那么重要,只是这两个序列会产生相同的字符串