Django dumpdata UTF-8(Unicode) [英] Django dumpdata UTF-8 (Unicode)
问题描述
有没有简单的方法从数据库转储 UTF-8 数据? / p>
我知道这个命令:
manage.py dumpdata> mydata.json
但是我在文件mydata.json中获得的数据,Unicode数据看起来像: / p>
name:\\\东\\\泰\\\香\\\港\\\五\\\金\\\有\\我想看到一个真正的Unicode字符串,如$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ code>全球卫星定位系统
(中文)解决方案django-admin.py dumpdata yourapp 可以转储为此目的。 p>
或者如果你使用MySQL,你可以使用 mysqldump 命令转储整个数据库。
和这个线程有许多方法来转储数据,包括手动方法。
更新:因为OP编辑了这个问题。
将JSON编码字符串转换为人可以使用这个字符串:
open(mydata-new.json,wb mydata.json)。read()。decode(unicode_escape)。encode(utf8))
Is there a easy way to dump UTF-8 data from a database?
I know this command:
manage.py dumpdata > mydata.json
But the data I got in the file mydata.json, Unicode data looks like:
"name": "\u4e1c\u6cf0\u9999\u6e2f\u4e94\u91d1\u6709\u9650\u516c\u53f8"
I would like to see a real Unicode string like
全球卫星定位系统
(Chinese).解决方案django-admin.py dumpdata yourapp could dump for that purpose.
Or if you use MySQL, you could use the mysqldump command to dump the whole database.
And this thread has many ways to dump data, including manual methods.
UPDATE: because OP edited the question.
To convert from JSON encoding string to human readable string you could use this:
open("mydata-new.json","wb").write(open("mydata.json").read().decode("unicode_escape").encode("utf8"))
这篇关于Django dumpdata UTF-8(Unicode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!