更新时间:2023-02-21 13:41:33
此答案仅在我们交换的评论之后:
This answer is just following the comments we've exchanged:
import json
js = r'{"result":"{\"key\":\"How are you? \"Great!\" he said. \"Coffee ?\"\"},{\"key\":\" 2. \"Why not sure\". They walked away\"}"}'
data1 = json.loads(js)
s = data1['result']
good_characters = [":","{","}", ","]
result = ""
for key, value in enumerate(s):
if (value == "\"" and s[key-1] not in good_characters) and (value == "\"" and s[key+1] not in good_characters):
result += '\''
else:
result += value
print (result)
输出
{"key":"How are you? 'Great!' he said. 'Coffee ?'"},{"key":" 2. 'Why not sure'. They walked away"}