十三、RF中對json的解析


A、需要安裝的庫

1.RequestsLibrary,安裝命令:pip2 install requests

2.HttpLibrary,安裝命令:pip2 install robotframework-httplibrary

3.HttpLibrary.HTTP,這個庫是在HttpLibrary中,HTTP是HttpLibrary的一個class

4.json,安裝命令:pip2 install jsonpatch

5.Collections,這個庫是python自帶的,直接引入即可

B、RF需導入的庫

1. HttpLibrary
2. HttpLibrary.HTTP-----------------------------------Get Json Value,parse json
3. json---------------------------------------------------loads
4. RequestsLibrary------------------------------------------to json

5.Collections--------------------------------------------------get from dictionary

C、取json中的值

 ${json_data}    set variable    {"id": "18701236666","code": 200,"msg": "ok","data": {"tag_list": [{"game_id": "28","game_name": "天天酷跑"},{"game_id": "29","game_name": "斗地主"}]}

${text01}             Get Json Value            ${json_data}           /id
${text02}             Get Json Value           ${json_data}            /data
${text03}             Get Json Value          ${json_data}            /data/tag_list

 

 

D、將json格式中[]轉化成python中dict格式

#將json[]中的值轉化成python dict格式
${data_to_json}                    to json                 ${text03}
log                ${data_to_json}
${data_parse_json}              parse json            ${text03}
log                ${data_parse_json}
${data_loads_json}              loads                      ${text03}
log                ${data_loads_json}

 

 

 

E、取值

#取值
${value}                           get from dictionary ${data_parse_json[0]}            game_name
log             ${value}
${value}                           get from dictionary ${data_parse_json[0]}            game_id
log             ${value}

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM