您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页搁家没法调试公司测试环境的请求数据了吗?

搁家没法调试公司测试环境的请求数据了吗?

来源:伴沃教育
当然有方法啦, 前提, 接口文档出了, 才好办了

比如, 如下"返回数据"给出

{
            "Status": 0,
            "CreateTime": 0,
            "UpdateTIme": 0,
}

ok , right now, hit the beats

$ step1, 创建 file

image.png

$ step2, 创建 把"返回数据" 复制到 file中

$ step3, 使用如下 读文件解析方法

// ----------------- 在家拿到json串 存入文件 解析 成字典 ------------------- //
+ (NSDictionary *)ObjectWithJsonStringFile:(NSString *)fileName
{
    
//    NSString *jsonStr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:@"json"] encoding:0 error:nil];
//    NSData *jsonData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    
    NSData * jsonData = [[NSData alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:@"json"] options:NSDataReadingMappedIfSafe error:nil];
    
    NSError * error ;
    NSMutableDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error: &error];
    
    if (error) {
        NSLog(@"error --------- %@",error); // null
    }
    
    return jsonDic;
}

把请求的方法 代替为这个咯 , 得到数据 , UI展示

NSDictionary * dic = [ViewController ObjectWithJsonStringFile:@"File"];

$ step4, MJExtension 或其它工具, 字典转模型, 最后得到UI model 展示, over~

借助OC读取json文件的方式得到字典(模拟网络请求得到数据),并可以自由更改文件内的各种数据,测试特定、极端等情况。完美~

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务