20230220
using json.loads()
.
import json
original_string = '{"John" : "01", "Rick" : "02", "Sam" : "03"}'
# printing original string
print("The original string is : " + str(original_string))
# using json.loads() method
result = json.loads(original_string)
# print result
print("The converted dictionary is : " + str(result))
最好是""
双引号。json默认双引号内的是dict。
参考:
[1] https://favtutor.com/blogs/string-to-dict-python
[2] https://stackoverflow.com/questions/39491420/python-jsonexpecting-property-name-enclosed-in-double-quotes
[3] https://www.geeksforgeeks.org/python-program-to-create-a-dictionary-from-a-string/
[4] https://favtutor.com/blogs/string-to-dict-python