簡體   English   中英

如何使用機器人框架更新/替換字典鍵類型的值為列表的字典/json文件中的值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM