// // 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
原文:http://my.oschina.net/u/2495938/blog/523274