将字符串转换为字典列表

时间:2020-09-28 15:27:27

标签: python json string list dictionary

我有一个表示为

的字符串
'[{"Name": "Joe","LastName":"Doe","Classes:"[CS3302,CS3306,CS4469]"},{"Name": "Mathew","LastName":"Lee","Classes:"[CS3312,CS3301,CS4161]"}]'

如何将其转换为词典列表并从中读取数据?

1 个答案:

答案 0 :(得分:0)

您可以使用json.loads()

import json

str = '[{"Name": "Joe","LastName":"Doe","Classes":"[CS3302,CS3306,CS4469]"},{"Name": "Mathew","LastName":"Lee","Classes":"[CS3312,CS3301,CS4161]"}]'

output = json.loads(str)

请注意,“班级”键后缺少引号