为uitableview单元解析json

时间:2013-06-10 12:51:46

标签: iphone objective-c json ios6

我有一个使用UITableview应用程序的应用程序。如果我单击带有JSON数据的UITableViewcell。我创建了一个UIViewController来显示UITableView中所选行的信息。我的要求是,如果单击UITableview单元格,相应的PDF文件将显示在模拟器中。我也开发了代码。但是pdf文件不会显示在模拟器上。我是编程新手。我怀疑是如何使用json parser.Plz下载PDF文件给我任何想法或给我发送任何示例代码。谢谢你提前 这是我的PDF网址:

UIViewController Class Reference

QLPreviewController Class Reference

这是我的示例代码。

JSONPARSERPDFVIEWCONTROLLER .M

-(void)loadData

{

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@""]];
connect=  [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

// delegate methods in json
-(void)connection:(NSURLConnection *)connectiondidReceiveResponse:(NSURLResponse *)response
{
    [_data setLength:0];
    NSLog(@"didReceiveResponse called");
}

//connection did receive data

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSMutableData *)data
{
    [_data appendData:data];
}

/ /connection did finish loading

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{
     NSError *jsonError = nil;
     id jsonObject = [NSJSONSerialization JSONObjectWithData:_data options:kNilOptions error:&jsonError];

    if ([jsonObject isKindOfClass:[NSArray class]]) 
    {
        //NSArray *jsonArray = (NSArray *)jsonObject;
    }
    else if ([jsonObject isKindOfClass:[NSDictionary class]])
    {

        NSDictionary *jsonDictionary = (NSDictionary *)jsonObject;  
        NSArray *array=[[NSArray alloc]init];
        array=[jsonDictionary objectForKey:@""];
        dataDictionary=[array objectAtIndex:0]; 
        NSLog(@"%@",dataDictionary);
    }
    [urlsArray addObject:[dataDictionary objectForKey:@"UIViewController"]];
    NSLog(@"%@",urlsArray);
    //[self dataLoadingFinished:responseString withData:downloadData];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{        
    //[connection release];     
    // = nil;
    NSLog(@"didFailWithError called");
}

uitableview.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    fileNameList = [[NSArray alloc]initWithObjects:@"UIViewController",@"QLPreview class",@"UIDocumentInteractionController", nil];    
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [fileNameList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text = [fileNameList objectAtIndex:indexPath.row];

    return cell;
}

#pragma mark - Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    jsonparser *jParser=[[jsonparser alloc]init];

    jParser.selectedIndex=indexPath.row;

    [self.navigationController pushViewController:jParser animated:YES];
}

0 个答案:

没有答案