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

    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];

    



你可能感兴趣的:(IOS学习积累)