关键字:Set Variable Get Json Value to json Get From Dictionary 具体关键字用法不再说明,可百度一下;
例:下面是某一个请求页面Response返回的数据,如下:
{"id":"1496654252","code":0,"msg":"ok","data":{"tag_list":[{"game_id":28,"enabledFlag":true,"game_name":"王者荣耀"},{"game_id":29,"enabledFlag":true,"game_name":"镇魔曲"}]}}
在RobotFramework中输入以下代码,可获取第一个“game_name”的值;
1 | ${json_data} | Set Variable | {"id":"1496654252","code":0,"msg":"ok","data":{"tag_list":[{"game_id":28,"enabledFlag":true,"game_name":"王者荣耀"},{"game_id":29,"enabledFlag":true,"game_name":"镇魔曲"}]}} | #设置变量 | |
2 | ${json_tag_list} | Get Json Value | ${json_data} | /data/tag_list | #先获取tag_list后的数据 |
3 | ${data_to_json} | To Json | ${json_tag_list} | #转json格式 | |
4 | ${game_name} | Get From Dictionary | ${data_to_json[0]} | game_name | #获取json第一个元素game_name的值,下标是从0开始; |
5 | log | ${game_name} | #打印输出 |