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

来源:互联网 发布:jsp连接sql server2005 编辑:程序博客网 时间:2024/04/27 07:50

    NSURL *url = [NSURLURLWithString:@"http://cst.stu.126.net/u/json/cms/ykt_protocol.json"];

   NSData *responseData = [NSDatadataWithContentsOfURL:url];

   NSError *jsonError;

   id result = [NSJSONSerializationJSONObjectWithData:responseDataoptions:kNilOptionserror:&jsonError];

   NSString *protocolStr = [resultvalueForKey:@"protocol"];

    [self.protocolWebviewloadHTMLString:protocolStrbaseURL: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];

    



0 0
原创粉丝点击