小编C.F*_*ang的帖子

使用 python -m json.tool 输出中文UTF-8

原始文本文件“chinese.txt”如下

\n

{"type":"FeatureCollection","text":"\xe4\xbd\xa0\xe5\xa5\xbd"}

\n

在 Mac 上,在终端中运行命令,如下所示

\n

$ cat chinese.txt | python -m json.tool

\n

输出是

\n
{\n    "text": "\\u4f60\\u597d",\n    "type": "FeatureCollection"\n}\n
Run 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。

\n

python json cjk

5
推荐指数
1
解决办法
1420
查看次数

标签 统计

cjk ×1

json ×1

python ×1