1
我使用json-simple從JSON文件讀取,改變 中的屬性並將它們寫回文件。這一條線:Java中的JSON:使用編碼的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.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