[英]Convert List to Json in Robot Framework
在调用特定的Get Regexp Matches
我得到了以下列表:
['{"result": 1, "error": { "namespace": "global", "reason": "unauthorized" } }']
当我以下列方式验证值时:
Should Be Equal ${response[0]['result']} 1
Should Be Equal ${response[0]['error']['namespace']} global
Should Be Equal ${response[0]['error']['reason']} unauthorized
然后我得到错误Resolving variable '${response[0]['result']}' failed: TypeError: string indices must be integers
根据文档(机器人框架的集合库), Get Regexp Matches
总是返回列表。 我想验证它们匹配的那些值(result=1,namespace=global,reason=unauthorized)但处理不起作用。 谢谢 !
谢谢@quamrana。 以这种方式解决:
${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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.