首页 > Web开发 > 详细

JSON实例

时间:2015-10-28 19:40:35      阅读:301      评论:0      收藏:0      [点我收藏+]
//
//  chonViewController.h
//  TestJson
//
//  Created by choni on 14-5-16.
//  Copyright (c) 2014年 choni. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface chonViewController : UITableViewController

//保存数据列表
@property(nonatomic,strong) NSMutableArray * listData; 

@end


与之对应的 chonViewController.m文件 代码如下:

//
//  chonViewController.m
//  TestJson
//
//  Created by choni on 14-5-16.
//  Copyright (c) 2014年 choni. All rights reserved.
//

#import "chonViewController.h"

@interface chonViewController ()

@end

@implementation chonViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    
    NSString * path = [[NSBundle mainBundle]pathForResource:@"Notes" ofType:@"json" ];
    NSData * jsonD


NSData * jsonData = [[NSData alloc] initWithContentsOfFile:path];
    
    NSError * error ;
    id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    if (!jsonObj || error) {
        NSLog(@"JSON解析失败");
    }
    self.listData = [jsonObj objectForKey:@"Record"];
    
    
}
#pragma mark - tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    NSMutableDictionary * dict = self.listData[indexPath.row];
    cell.textLabel.text = [dict objectForKey:@"Content"];
    cell.detailTextLabel.text = [dict objectForKey:@"CDate"];
    return cell ;
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
















































JSON实例

原文:http://my.oschina.net/u/2495938/blog/523274

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!