您的位置:首页 > 移动开发

获取json格式的数据并显示在webview上

2015-09-30 09:25 555 查看
NSURL *url = [NSURLURLWithString:@"http://cst.stu.126.net/u/json/cms/ykt_protocol.json"];
NSData *responseData = [NSDatadataWithContentsOfURL:url];
NSError *jsonError;
id result = [NSJSONSerializationJSONObjectWithData:responseData
options:kNilOptions
error:&jsonError];
NSString *protocolStr = [result
valueForKey:@"protocol"];
[self.protocolWebviewloadHTMLString:protocolStr
baseURL:nil];

// if (!self.loadingMaskView.hidden) {
// [self.loadingMaskView startLoadingWithTip:@"努力载入中..."];
// }
// NSURL *url = [NSURL URLWithString:@"http://cst.stu.126.net/u/json/cms/ykt_protocol.json"];
// NSData *responseData = [NSData dataWithContentsOfURL:url];
// NSError *jsonError;
// id result = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&jsonError];
// NSString *protocolStr = [result valueForKey:@"protocol"];
//
// if(protocolStr){
// [self.loadingMaskView stopLoadingSuccessfully];
// //将协议显示到webView
// //加载URL
// [self.protocolWebview loadHTMLString:protocolStr baseURL:nil];
// }
// else{
// [self.loadingMaskView stopLoadingFailedWithTip:@"点击屏幕,重新加载" reloadable:YES];
// }

//
// if (!self.loadingMaskView.hidden) {
// [self.loadingMaskView startLoadingWithTip:@"努力载入中..."];
// }
// NSString *protocolStr = [EduSystem sharedInstance].protocol;
// if(protocolStr){
// [self.loadingMaskView stopLoadingSuccessfully];
// //将协议显示到webView
// //加载URL
// [self.protocolWebview loadHTMLString:protocolStr baseURL:nil];
// }
// else{
// [self.loadingMaskView stopLoadingFailedWithTip:@"点击屏幕,重新加载" reloadable:YES];
// }

// //先从网络上拿数据,如果有网络,显示网络版,否则显示本地版本协议
// NSURL *url = [NSURL URLWithString:@"http://cst.stu.126.net/u/json/cms/ykt_protocol.json"];
// NSData *responseData = [NSData dataWithContentsOfURL:url];
// NSError *jsonError;
// id result = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&jsonError];
// NSString *protocolStr = [result valueForKey:@"protocol"];
//
// if(!protocolStr){
// //网络未获取到
// Protocol *protocol = [Protocol getProtocolWithType:1];
// protocolStr = [protocol valueForKey:@"content"];
// }
// [self.protocolWebview loadHTMLString:protocolStr baseURL:nil];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: