简体   繁体   中英

Convert List to Json in Robot Framework

after calling specific Get Regexp Matches I got following list:

['{"result": 1, "error": { "namespace": "global", "reason": "unauthorized" } }']

When I am verifying values in following way :

Should Be Equal   ${response[0]['result']}  1
Should Be Equal   ${response[0]['error']['namespace']}  global
Should Be Equal   ${response[0]['error']['reason']}  unauthorized

Then I got error Resolving variable '${response[0]['result']}' failed: TypeError: string indices must be integers Based on documentation (Robot Frameworks's Collection Library), Get Regexp Matches always return list. I'd like to verify those values that they matched (result=1, namespace=global, reason=unauthorized) but handling is not working. Thanks !

Thanks @quamrana. Solved in this way:

${response} =  Evaluate    json.loads('''${response[0]}''')    json
Should Be Equal   ${response['result']}  1
Should Be Equal   ${response['error']['namespace']}  global
Should Be Equal   ${response['error']['reason']}  unauthorized

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM