美文网首页
搁家没法调试公司测试环境的请求数据了吗?

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

作者: wustzhy | 来源:发表于2017-08-27 11:02 被阅读8次
    当然有方法啦, 前提, 接口文档出了, 才好办了

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

    {
                "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文件的方式得到字典(模拟网络请求得到数据),并可以自由更改文件内的各种数据,测试特定、极端等情况。完美~

    相关文章

      网友评论

          本文标题:搁家没法调试公司测试环境的请求数据了吗?

          本文链接:https://www.haomeiwen.com/subject/nyebdxtx.html