需求:读取文件,每行为一个json,需要改动某些节点,并重新写入文件中

方法:编码格式统一UTF8,读取文件后,fout=open("test","w"),fout.write(json.dumps(data,ensure_ascii=False)+"\n"),这种方式会导致写入的文件中文不能显示。

解决办法,我们需要以指定的编码方式打开输出文件import codecs;codecs . open ( "test" , 'w' , 'utf-8' ),这样就能够正常写入了。原因貌似是python内部处理是Unicode,这是打开文件也是Unicode,导致输出不正常。

GitHub 加速计划 / js / json
55
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:26 天前 )
281d1e92 1 天前
7421ac31 Changed the example code in the documentation from copy initialization to direct initialization for `json::json_pointer`. This prevents compilation errors caused by the constructor being explicit. 2 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐