【发布时间】:2019-10-24 11:43:42
【问题描述】:
如何使用 python 将以下字符串转换为 JSON?
str1 = "{'a':'1', 'b':'2'}"
【问题讨论】:
-
那个字符串是 JSON。您的意思是如何将该 JSON 解析为 Python 字典?
-
您好,欢迎来到 SO。您可能想了解How to Ask 并尝试自己做最少的搜索工作。提示:这是in the stdlib。
-
这能回答你的问题吗? Convert JSON string to dict using Python
-
这个字符串不是 JSON。它在键和值周围使用单引号。
-
str1 = str1.replace("'", '"')然后使用链接中的解决方案。
标签: json python-3.x