如果AWS输出的Python JSON中包含单引号,可以使用json.loads()
方法将其转换为Python字典或列表,并在必要时使用replace()
方法删除单引号。
以下是一个示例代码:
import json
aws_json = "{'name': 'John', 'age': 30}"
# 使用replace()方法删除单引号
aws_json = aws_json.replace("'", "\"")
# 使用json.loads()方法将字符串转换为Python字典
python_dict = json.loads(aws_json)
print(python_dict)
# 输出: {'name': 'John', 'age': 30}
在上面的示例中,replace("'", "\"")
将所有的单引号替换为双引号。然后,使用json.loads()
方法将转换后的字符串转换为Python字典。最后,可以按照需要访问和操作Python字典中的数据。