robot framework 接口返回值的处理
接口返回值为:
1 {"data":{"data":[[{"key1":"value1"},{"key2":"value2"},{"key3":"value3"}],[{"key11":"value11"},{"key12":"value12"},{"key13":"value13"}]]},"result":"1"} 2 3 #格式化 4 5 { 6 "data": { 7 "data": [ 8 [ 9 { 10 "key1": "value1" 11 }, 12 { 13 "key2": "value2" 14 }, 15 { 16 "key3": "value3" 17 } 18 ], 19 [ 20 { 21 "key11": "value11" 22 }, 23 { 24 "key12": "value12" 25 }, 26 { 27 "key13": "value13" 28 } 29 ] 30 ] 31 }, 32 "result": "1" 33 }
想取 value13,可以这样写
1 Comment ${res_utf8} decodeutf8 ${res_agree} #转码,如果不需要可注释 2 ${res} Set Variable {"data":{"data":[[{"key1":"value1"},{"key2":"value2"},{"key3":"value3"}],[{"key11":"value11"},{"key12":"value12"},{"key13":"value13"}]]},"result":"1"} 3 ${res_json} to json ${res} #先将返回值转成json,如果不需要可注释 4 ${res_data} Get From Dictionary ${res_json} data #取第一层data 5 ${res_data2} Get From Dictionary ${res_data} data #取第二层data 6 ${res_list} Get From List ${res_data2} 1 #取list中第二个 7 ${res_list2} Get From List ${res_list} 2 #取list中第三个 8 ${res_key12} Get From Dictionary ${res_list2} key13 #取value13
结果如下: