1

Im using json-simple to read from JSON files, to alter the attributes inside and to write them back to a file. This a line:

{"username": "M\u00e4nnlich2", "url": "http://www.dslr-forum.de/showthread.php?t=1303001"}

Problem: I get this as a Map when I load them to a JSONObject:

{"username": "Männlich2", "url":"http:\/\/www.dslr-forum.de\/showthread.php?t=1303001"}

I want to keep the coding "M\u00e4nnlich2" and the url shouldnt get escapes.

Is this normal? How can i keep the encoding when I parse it into a JSONObject? Or should I use a different JSON library?

Here is some Example code:

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
4

1 回答 1

1

This is absolutely correct. JSON cannot remember original formatting once converted into internal representation. No library would help.

Actually it's not that much about JSON, simply those two sequences result into the same String...

于 2015-11-11T15:22:22.340 回答