#在蓝懿学习iOS的日子#day19

今天没有学习什么新的知识,我都是在反复使用这里两天学习的内容进行知识的展示,让一个内容变得丰富 1、web view的使用 搭建 然后编写代码 @property (weak, nonatomic) IBOutlet UIWebView *myWV; @property (weak, nonatomic) IBOutlet UITextField *myTF; @end @implementation ViewController - (IBAction)clicked:(id)sender { NSURL *url = [NSURL URLWithString:self.myTF.text]; //创建请求 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [self.myWV loadRequest:request]; } 2,创建解析类jsonParser +(TrainInfo *)parserTrainInfoWithDic:(NSDictionary *)dic{ NSDictionary *resultDic = dic[@"result"]; TrainInfo*t = [[TrainInfo alloc]init]; t.name =resultDic[@"name"]; t.start = resultDic[@"start"]; t.end = resultDic[@"end"]; t.starttime = resultDic[@"starttime"]; t.endtime = resultDic[@"endtime"]; t.mileage = resultDic[@"mileage"]; NSArray*station_listArr = resultDic[@"station_list"]; for (NSDictionary*stationDic in station_listArr) { Station*s = [[Station alloc]init]; s.train_id = stationDic[@"train_id"]; s.arrived_time = stationDic[@"arrived_time"]; s.leave_time = stationDic[@"leave_time"]; s.mileage=stationDic[@"mileage"]; [t.station_list addObject:s]; } return t; } 3、Web Utils,网络端口类 +(TrainInfo *)requstTrainInfoWithTarinCode:(NSString *)code{ NSString*path = [NSString stringWithFormat: @"http://apis.juhe.cn/train/s?name=%@&key=30ad4a93a8cb60dead364ec6de779427",code]; path =[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // 此内容,修改为上一行 path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:path]; NSData *data = [NSData dataWithContentsOfURL:url]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; TrainInfo *ti = [JsonParser parserTrainInfoWithDic:dic ]; return ti; }

转载于:https://www.cnblogs.com/odileye/p/4967302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值