在Python中替换双引号内部的双引号

2024-03-29 05:35:48 发布

您现在位置:Python中文网/ 问答频道 /正文

JSON文件 { “data”:“{”id”:“123”,“unit”:“metric”,“location”:“NYC”} }你知道吗

必须是

你知道吗{ “data”:“{id':'123',unit':'metric',location':'NYC'}” }你知道吗

基本上,双引号中的任何双引号都需要变成单引号

尝试

import re
re.sub('\w[: ]*"\w','',str)

不起作用


Tags: 文件importreidjsondataunitlocation