问题描述

dic = {'words':"帮我打开电视"}
>>> import json
>>> json.dumps(dict)
'{"words": "\\u5e2e\\u6211\\u6253\\u5f00\\u7535\\u89c6"}'

输出中文依然为unicode编码.

原因

json解析中文会默认使用的ascii编码.

解决方法

指定ensure_ascii=False

json.dumps(dict,ensure_ascii=False)
'{"words": "帮我打开电视"}'
GitHub 加速计划 / js / json
53
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:17 天前 )
230bfd15 Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.6.0 to 4.7.0. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/ce3cf9537a52e8119d91fd484ab5b8a807627bf8...38ecb5b593bf0eb19e335c03f97670f792489a8b) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-version: 4.7.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 5 天前
e9391dc5 Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.1 to 4.02. - [Release notes](https://github.com/lukka/get-cmake/releases) - [Commits](https://github.com/lukka/get-cmake/compare/57c20a23a6cac5b90f31864439996e5b206df9dc...ea004816823209b8d1211e47b216185caee12cc5) --- updated-dependencies: - dependency-name: lukka/get-cmake dependency-version: '4.02' dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 7 天前
Logo

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

更多推荐