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