java - Java 中的 JSON : Using encoded JSON files and keeping it

标签 java json file encoding json-simple

我使用 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/

相关文章:

java - 如何显示Saml断言节点?

java - (Android Java Sqlite)由于IP地址导致连接数据库失败时如何提示toast

java - 如何在java中处理圆和半圆碰撞的 react ?

java - 将 JSON 序列化为 Scala 案例类

java - 如何将 thrift 对象转换为可读字符串并将其转换回来?

c - 在 C 中使用 "\n"和 "\0"以外的特殊字符

javascript - stringByEvaluatingJavaScriptFromString 问题

java - 彩票程序(ArrayList)

java - Couchbase DefaultOrphanResponseReporter 观察到的孤儿 react

python - 值错误: too many values to unpack with JSON File and Requests Post Call