从嵌套的json中删除反斜杠

时间:2019-07-08 19:49:28

标签: json python-3.x encode

我收到一个数据库请求的响应,该请求存储在列表中,并作为参数response发送到以下函数:

phython3

def sendReponse(status, myStatusCode, message, response):
if myStatusCode == 200:
    cleaned = json.loads(response)
      #       {
      #      "instanceIdJobCreator": "instance-x44",
      #      "component": "mapper",
      #      "jobParameter": "{\"alice\":\"bob\",\"foo\":\"bar\",\"va1\":\"bmw-x-5\"}",
      #      "jobStatus": "created",
      #      "itemType": "job",
      #      "createTime": "2019-07-06T14:57:31.577Z",
      #      "id": "job-1GXSBjK1pI-b9gs88Azwv-BCvkU-mO6"
      #       }
    data = {"status": status, 
            "info": message,
            "data": cleaned
            }
else:
    data = {"status": status, 
            "info": message
            }
headers = {'Content-type': 'application/json'}
message = dict(statusCode=myStatusCode,
            isBase64Encoded=False,
            headers=headers,
            body=data)
return message

我现在遇到的问题是“ jobParamter”中的嵌套项目添加了反斜杠:

"jobParameter": "{\"alice\":\"bob\",\"foo\":\"bar\",\"va1\":\"bmw-x-5\"}"

是否可以删除它们?我已经尝试了response.replace('\“','”'),但是由于某种原因,响应字符串没有替换反斜杠...

0 个答案:

没有答案