[英]How to update/replace value in the dictionary/json file where the value of the dictionary's key type is list using robot framework
我正在尝试将值“四”更新为“四”
json格式:
"Num" : {
"Roman": [
{
"word_rep": {
"IV": [
"Four"
]
}
}
]
}
代码:
${file} Get File file1.json
${json_file} Evaluate json.loads('''${file}''') json
${new_val} set variable four
set to dictionary ${json_file["Num"]['Roman'][0]['word_rep']} IV[0]=${new_val}
当我尝试上面的代码时,我在现有字典中添加了一个新字典({'IV[0]':'four'})我想替换该值而不是新添加的值。
有人可以帮我从这里出去吗。
提前致谢
问题是您尝试使用字典关键字来更新列表。
即 Robot Framework 会将IV[0]
视为字符串,并且由于键不存在,因此会将其设置为字典作为新条目。
要更新列表,您需要将其称为带有Set List Value 的列表。
下面应该相应地工作。
Set List Value ${json_file["Num"]['Roman'][0]['word_rep']['IV']} 0 ${new_val}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.