1. 接口文件代码
<?php
$jsonStr = '{"name":"一级建造师市政全科","id":200802,"secondCategory":708,"CategoryList":[{"cname":"管理","id":2040},{"cname":"经济","id":2030},{"cname":"法规","id":230}]}';
echo $jsonStr;
?>
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];
}];
网友评论