Python string.split 不符合我的预期

Ben*_*ist 0 python json deserialization

我有一个字符串,里面有一堆奇怪的东西,我想分解成一个列表:

"44":{"1":4.6,"0":1.53,"2":7.2},"53":{"1":4.2,"0":1.4,"2":6.75},"121":{"1":3.2,"0":1.6,"2":6}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望:

"44":{"1":4.6,"0":1.53,"2":7.2}
"53":{"1":4.2,"0":1.4,"2":6.75}
"121":{"1":3.2,"0":1.6,"2":6}
Run Code Online (Sandbox Code Playgroud)

但我会满足于在每个} 处进行拆分。

mystring.split('}')似乎出于某种原因将我的字符串拆分为每个字符一个元素的列表。不知道我做错了什么。帮助!

Tim*_*ker 7

这几乎看起来像有效的 JSON。

>>> s = '"44":{"1":4.6,"0":1.53,"2":7.2},"53":{"1":4.2,"0":1.4,"2":6.75},"121":{"1":3.2,"0":1.6,"2":6}'
>>> import json
>>> d = json.loads("{" + s + "}")
>>> d
{'53': {'2': 6.75, '0': 1.4, '1': 4.2}, '44': {'2': 7.2, '0': 1.53, '1': 4.6}, '
121': {'2': 6, '0': 1.6, '1': 3.2}}
>>> for key,value in d.items():
...    print("Key: {0} - Value: {1}".format(key,value))
...
Key: 53 - Value: {'2': 6.75, '0': 1.4, '1': 4.2}
Key: 44 - Value: {'2': 7.2, '0': 1.53, '1': 4.6}
Key: 121 - Value: {'2': 6, '0': 1.6, '1': 3.2}
Run Code Online (Sandbox Code Playgroud)