同一个正则表达式匹配多个响应结果值,之前都是添加多个正则表达式,一个一个去获取需要的值,比较麻烦;今天尝试了一下用一个正则表达式获取响应中所有需要的值,使用这种方式也能够获取多个结果中指定的值,完美省事!
我要获取如下响应报文中首次出现的两个值(barnType 和 trainScheduleBarnId 的值)目标是:{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271}?
?
{"content":{"barns":[{"available":0,"barnNo":"01","barnType":"STX1","recommend":0,"spaceStatus":"FULL","trainScheduleBarnId":3271},{"available":1,"barnNo":"02","barnType":"STX2","recommend":1,"spaceStatus":"EMPTY","trainScheduleBarnId":3272},{"available":0,"barnNo":"03","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3273},{"available":0,"barnNo":"04","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3274},{"available":1,"barnNo":"05","barnType":"STX1","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3275},{"available":1,"barnNo":"06","barnType":"STX2","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3276},{"available":0,"barnNo":"07","barnType":"STX3","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3277},{"available":0,"barnNo":"08","barnType":"STX4","recommend":0,"spaceStatus":"EMPTY","trainScheduleBarnId":3278}],"count":3,"endStationId":2101,"endStationName":"石家庄","endTime":1525491060000,"id":414,"startStationId":2401,"startStationName":"太原","startTime":1525059060000,"trainNo":"K707"},"errorCode":null,"errorMsg":null,"status":"OK"}
返回响应结果顺序都是不变的,想每次获取不同参数的值,怎么办?只需要小小的改动即可
?
* 0 表示随机
* -1 表示全部
* 1表示第一个
* 2表示第二个
* ......
感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
?
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取?