【问题标题】:Remove Unicode in a Dictionary删除字典中的 Unicode
【发布时间】:2017-04-20 13:17:08
【问题描述】:

我在从字典中删除 unicode 时遇到问题。我尝试使用编码方法,但“u”仍在打印出来。我正在尝试将我的数据放入 JSON 编辑器,但它不喜欢 unicode。任何帮助都会很棒!

原始打印声明:

print get_photo_data(photo_ids)

尝试使用编码方法:

print get_photo_data(photo_ids.encode('utf-8'))

一些带有 unicode 的 JSON:

{u'photo': {u'people': {u'haspeople': 0}, u'dateuploaded': u'1492693219', u'owner': {u'username': u'jrobfoto.com', u'realname': u'Jonathan Robson', u'nsid': u'26449190@N00', u'iconserver': u'1360', u'location': u'Naperville, USA', u'path_alias': u'robsonj', u'iconfarm': 2}, u'publiceditability': {u'canaddmeta': 1, u'cancomment': 1}, u'id': u'34157653485', u'title': {u'_content': u'shared with pixbuf'}, u'media': u'photo', u'tags':

【问题讨论】:

标签: python json methods unicode


【解决方案1】:

你可以这样打印:-

import json
print(
    json.dumps(
        get_photo_data(photo_ids),
        sort_keys=True,
        indent=4,
        separators=(',', ': ')
    )
)

here for more

【讨论】:

    猜你喜欢
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多