zoukankan      html  css  js  c++  java
  • 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 }
    View Code

    想取  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

    结果如下:

  • 相关阅读:
    Save the problem!
    Divisiblity of Differences
    定个小目标
    Faulty Robot
    反片语 uva 156(map的使用
    Input is terminated by EOF.
    uva10815 andy的字典(set的应用)
    uva-101 搬砖问题(不定长数组vector的使用)
    回文串uva401(清简出风尘)
    WERTYU (善用常量数组
  • 原文地址:https://www.cnblogs.com/whycai/p/12215129.html
Copyright © 2011-2022 走看看