如何json转储带有外来字符的字典 [英] How to json dump a dict with foreign characters

查看:116
本文介绍了如何json转储带有外来字符的字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常会打印字典:

def print_row(self):
    print(json.dumps(self.example_entry, indent=4, sort_keys=True))

但是,这就是我现在得到的:

However, here is what I now get:

>>> f.print_row()
{
    "#export_date": "1475226000146",
    "artist_id": "1159638168",
    "artist_type_id": "1",
    "is_actual_artist": "1",
    "name": "\uc2e4\ubc84 \ud14c\uc774\ube14",
    "view_url": "http://itunes.apple.com/artist/silbeo-teibeul/id1159638168?uo=5"
}

我如何打印name字段,就像在dict中那样打印,例如:

How would I get the name field printed as it would print in the dict, such as:

>>> print(f.example_entry)
{'#export_date': '1475226000146', 'artist_id': '1159638168', 'name': '실버 테이블', 'is_actual_artist': '1', 'view_url': 'http://itunes.apple.com/artist/silbeo-teibeul/id1159638168?uo=5', 'artist_type_id': '1'}

推荐答案

json.dumps(..., ensure_ascii=False)

{
    "#export_date": "1475226000146",
    "artist_id": "1159638168",
    "artist_type_id": "1",
    "is_actual_artist": "1",
    "name": "실버 테이블",
    "view_url": "http://itunes.apple.com/artist/silbeo-teibeul/id1159638168?uo=5"
}

这篇关于如何json转储带有外来字符的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆