ios|ios 打桩

1. 接口文件代码


或者直接把json 内容写进文件jsonTest.json 作用相同
ps :前提是自己win7搭建一个Apache 服务,感觉这样比较真实
2. ios 请求
NSURL * url = [NSURL URLWithString:@"http://172.16.16.207:50080/jsonTest.php"]; //接口地址 NSURLRequest * requst = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:requst queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {NSDictionary * dataD = data.JSONObject; // 采用第三方json 库转换成字典 CategoryModel * model = [CategoryModel objectWithKeyValues:dataD]; }];

----另外的方式-------基于thinkphp5框架搭建的apache 环境
class Index{ public function data(){ $data = https://www.it610.com/article/['data' => [['name'=> 'lee','age'=> '12'],['name'=> 'zhang','age'=> '33']], 'status' => ['code'=> 200,'msg' => 'ok'] ]; $json = json($data); return $json; } }调用方式:http://localhost/admin/index/data

【ios|ios 打桩】效果如下:

ios|ios 打桩
文章图片
image.png

    推荐阅读