Atri Dave
Atri Dave

Reputation: 162

How to convert unicode to dictionary in python

I know this kind of question has been asked before but I am not able to find solution for my problem

My function is returning me unicode in this format

{"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"}

while checking with type it shows it is <type 'unicode'>

I tried with ast.literal_eval(myver) but no luck which are other ways to convert it to python dictionary?

Upvotes: 4

Views: 7170

Answers (1)

cs95
cs95

Reputation: 402413

This looks like JSON. You might want to convert it to a python dict using python's inbuilt json module:

import json    
data = json.loads(myver)

Upvotes: 1

Related Questions