从unicode文本中获取元素

时间:2016-03-14 13:21:32

标签: python python-2.7

我有一个字符串:

u'{"nick":"NICK","name":"NAME","email":"name@example.com","phone_gsm":"","phone":"","birthday":"","location":"UK","address":"","job":"","gender":"male","permission_of_contact":"NO"}'

我需要获取正确的数据,因此我需要获取用户的昵称,用户的电子邮件等。有没有办法获取它们?

谢谢。

1 个答案:

答案 0 :(得分:3)

使用json模块

import json
my string = u'{"nick":"NICK","name":"NAME","email":"name@example.com","phone_gsm":"","phone":"","birthday":"","location":"UK","address":"","job":"","gender":"male","permission_of_contact":"NO"}'

data = json.loads(my_string)