def preprocess_web_json(json_str,key_name_first="front_canvas",key_name_second="json_param"):
json_str = json_str.replace("\\n","")
json_str = json_str.replace("\\","")
json_str = json_str.replace(":",":")
json_str = re.sub('\n',"",json_str)
json_str = re.sub("\s","",json_str)
json_str = re.sub('"\[',"[",json_str)
#存在这种情况,所以需要"/"[
json_str = re.sub('"\[',"[",json_str)
json_str = re.sub('\]"',"]",json_str)
json_str = re.sub('\]"',"]",json_str)
json_str = re.sub('"\{',"{",json_str)
json_str = re.sub('"\{',"{",json_str)
json_str = re.sub('\}"',"}",json_str)
json_str = re.sub('\}"',"}",json_str)
json_str = json_str.replace(key_name_first,'"'+key_name_first+'"')
json_str = json_str.replace(key_name_second,',"'+key_name_second+'"')
json_str = "{"+json_str+"}"
return json_str
如图所示:如果需要替换的字符串中为 { [符合需要转义