【发布时间】:2020-06-28 11:02:36
【问题描述】:
在调用特定的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
基于文档(Robot Frameworks 的集合库),Get Regexp Matches 始终返回列表。
我想验证它们匹配的那些值(result=1,namespace=global,reason=unauthorized)但处理不起作用。
谢谢 !
【问题讨论】:
-
看起来
response是一个包含单个字符串的列表。你应该使用resp0 = json.loads(response[0]),然后使用resp0['result']等等。 -
这能回答你的问题吗? Parsing Json in Robot Framework
标签: python json robotframework