原始文本文件“chinese.txt”如下
\n{"type":"FeatureCollection","text":"\xe4\xbd\xa0\xe5\xa5\xbd"}
在 Mac 上,在终端中运行命令,如下所示
\n$ cat chinese.txt | python -m json.tool
输出是
\n{\n "text": "\\u4f60\\u597d",\n "type": "FeatureCollection"\n}\nRun Code Online (Sandbox Code Playgroud)\n如何添加参数以避免“\\u4f60\\u597d”并获得“\xe4\xbd\xa0\xe5\xa5\xbd”
\n我喜欢做的是从 shell 中使用python -m json.tool而不修改json.tool. 一个常见的用例是重新格式化 UTF-8 编码的 json 文件,并保留中文字符,而不是像 \\uxxxx。