【问题标题】:How to convert unicode to dictionary in python如何在python中将unicode转换为字典
【发布时间】:2017-08-17 15:43:10
【问题描述】:

我知道以前有人问过这类问题,但我无法找到解决问题的方法

我的函数以这种格式返回 unicode

{"set_id": "Rome", "group": "human", "attachments": null, , "object_type": "Prop", "attached": null, "tag_id": "prop", "Double Click": "reference", "files": "/makeup/Data/weapons/rifle", "source": "cupid", "attachment_label": null, "require_attachment": true, "rate": "high", "location": "/set2/ep1/Objects/weapons/machineguns/gun.txt", "attachment_type": null, "icon_path": "/resource/asset_manager/icons/rifle.bmp"}

检查类型时显示它是<type 'unicode'>

我尝试了ast.literal_eval(myver),但没有运气 还有哪些其他方法可以将其转换为 python 字典?

【问题讨论】:

  • 对我来说这看起来像JSON-String。你试过import json; json.loads(myver)吗?
  • @Felk 这是无效的 JSON。
  • 该示例包含此位:... null, , "object_type": ...。双逗号确实是无效的 JSON,但不清楚 OP 是否意味着存在

标签: python dictionary unicode


【解决方案1】:

这看起来像 JSON。您可能希望使用 python 的内置 json 模块将其转换为 python dict

import json    
data = json.loads(myver)

【讨论】:

    猜你喜欢
    • 2011-11-26
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多