• 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

    结果如下:

  • 相关阅读:
    集合 Subset Sums
    resin config 中文(resin.xml)
    resin4 简单学习
    什么是敏捷软件测试
    10个热门IT证书
    LoadRunner监控Linux服务器
    Agile 敏捷开发
    戴明PDCA方法
    【转】什么是内存泄露? 内存泄露检测工具
    LoadRunner常见问题
  • 原文地址:https://www.cnblogs.com/whycai/p/12215129.html
Copyright © 2020-2023  润新知