#在蓝懿学习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;
}