【发布时间】:2019-09-13 07:32:49
【问题描述】:
在 Python 中,如何转换如下所示的字符串对象
"{
apartment=false,
walls=[{min_height=18, max_height=3, color=WHITE}],
appliances=[{type=[oven, washing_machine, microwave, drying_machine,
dish_washer, television]}],
rooms=[{bathroom=true, floor=2}, {bedroom=true, floor=[2,3], needs_renovation=EXCLUDE}],
value=[{sale_price=9003.01, occupied=true, family_unit=UNKNOWN}]
}"
像这样的字典对象?
{
"apartment": False,
"walls": [{"min_height": 18, "max_height": 3, "color": "WHITE"}],
"appliances": [{"type": ["oven", "washing_machine", "microwave", "drying_machine",
"dish_washer", "television"]}],
"rooms": [{"bathroom": True, "floor": 2}, {"bedroom": True, "floor":[2,3], "needs_renovation": "EXCLUDE"}],
"value": [{"sale_price": 9003.01, "occupied": True, "family_unit": "UNKNOWN"}]
}
我使用的是Simple way to convert a string to a dictionary,但它并没有让我走得更远,因为我无法处理嵌套的字典和列表。
【问题讨论】:
标签: python json string dictionary