zoukankan      html  css  js  c++  java
  • 如何处理接口响应结果分析

    状态码
    errorcode
    message
    json
    code和message的json 文件
     
    {
    "api3/getbanneradvertver2":[
    {"1006":"token error"},
    {"1006":"用户名错误"},
    {"1006":"密码错误"}
    ],
    "api3/beta4":[
    {"1006":"登陆成功"},
    {"1006":"用户名错误"},
    {"1006":"密码错误"}
    ],
    "api3/getcourseintro":[
    {"1006":"token error"},
    {"10001":"用户名错误"},
    {"10002":"密码错误"}
    ]
    }
    读取json格式的代码:
    def read_json(file_name=None):
    if file_name == None:
    file_path = base_path+"/Config/user_data.json"
    else:
    file_path = base_path+file_name
    with open(file_path,encoding='UTF-8') as f:
    data = json.load(f)
    return data

    def get_value(key,file_name=None):
    data = read_json(file_name)
    return data.get(key)
    封装校验message 和code 
    #coding=utf-8
    import sys
    import os
    import configparser
    base_path = os.getcwd()
    sys.path.append(base_path)
    import json
    from deepdiff import DeepDiff
    from Util.handle_json import get_value
    #print(get_value('api3/getbanneradvertver2',"/Config/code_message.json"))
    '''[
    {"1006,":"token error"},
    {"10001":"用户名错误"},
    {"10002":"密码错误"}
    ]'''

    def handle_result(url,code):
    data = get_value(url,"/Config/code_message.json")
    if data !=None:
    for i in data:
    message = i.get(str(code))
    if message:
    return message
    return None

    def get_result_json(url,status):
    data = get_value(url,"/Config/result.json")
    if data !=None:
    for i in data:
    message = i.get(status)
    if message:
    return message
    return None
  • 相关阅读:
    angularIO 路由守卫
    vue-property-decorator用法
    windows mysql 忘记密码
    OSPF 做负载均衡
    NLB 部署网络负载平衡
    flexible.js 布局详解
    python setup.py 构建
    python Zope.interface安装使用
    lnmp菜单
    linux下的文件删除原理
  • 原文地址:https://www.cnblogs.com/LinxiHuang/p/13191090.html
Copyright © 2011-2022 走看看