[英]find single quote with in double quote string and replace
我有一个 json 文件,其中包含如下数据。 我想用双引号字符串(第 2 行)中的空格替换单引号(O'Connor)。 谁能帮助我如何使用 python 实现这一目标? 我是一个试图理解的初学者。
测试.json
{'Location': 'near Roe Hwy (3); Forrestfield; in Perth;', 'Name': "Sam", 'Salary': 1000, 'deptno': 10, 'dname':'sales'}
{'Location': **"near 133 Garling St; O'Connor; in Perth;",** 'Name': "Jam", 'Salary': 3000, 'deptno': 40, 'dname':'sales'}
output 应该像
{'Location': 'near Roe Hwy (3); Forrestfield; in Perth;', 'Name': "Sam", 'Salary': 1000, 'deptno': 10, 'dname':'sales'}
{'Location': **"near 133 Garling St; OConnor; in Perth;"**, 'Name': "Jam", 'Salary': 3000, 'deptno': 40, 'dname':'sales'}
你可以尝试这样的事情:
text = "\"near 133 Garling St; O'Connor; in Perth;\""
start = text.find("\"")
end = text[start+1:].find("\"")
text[start+1:end].replace('\'','')
在示例中,文本变量是您的 json 响应的一部分,被解析为字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.