RobotFramework解析返回json断言
返回的json数据为:
{ "data": { "advertisingUnitId": 0 }, "message": "成功", "status": 0, "time": 1542950193345 }
想要获取的是 advertisingUnitId 的值0
${result_json}为接口返回,则可以这样写:${result_json['data']['advertisingUnitId']}
接口更复杂的情况:
{ "api": "api.name", "v": "1.0", "code": "10000", "error_msg": "success", "data": { "userlist": [{ "uid": "94901", "nickName": "test1", }, { "uid": "1010640", "nickName": "test2", }, { "uid": "1012130", "nickName": "test3", }] } }
想要获取第一个nickNanme的值test1:${result_json['data']['userlist'][0]['nickName']}
其实就是一层层的剥,字典取值用dict['key']方式,元组取值用tup[index]方式