代码:

    1. #正则表达,获取code值
    2. import re
    3. response = '{"code":"0000","msg":"成功","data":{"accessToken":"566ede49-f272-41c3-8e93-5bf88d3db48e",' \
    4. '"tokenType":"bearer","refreshToken":"9327ef51-fc7f-4cc8-8c47-84357d8aa192","expiresIn":"179874",' \
    5. '"userId":"5541","modifyPasswordFlag":0},"success":true}'
    6. matchObj = re.findall(r'"code":"(.+?)"',response) #正则提取code,返回列表
    7. print("code:"+matchObj[0])

    执行结果:

    1. code:0000