`
jsntghf
  • 浏览: 2478454 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

JSON的解析

    博客分类:
  • iOS
阅读更多

1、将JSON中的所有文件拷入项目的Classes中

 

2、新建一个MyDataSource类,用来解析JSON

 

@interface MyDataSource : NSObject {

}

+ (id)dataSource;
@end

 

 

实现文件中,需要导入JSON类

 

#import "MyDataSource.h"
#import "SBJson.h"

@implementation MyDataSource
+ (id)dataSource
{
	NSString* JSONString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"resources" ofType:@"json"]
													 encoding:NSUTF8StringEncoding error:nil];
	return [JSONString JSONValue];
}
@end

 

3、在你的类中声明一个数组,并将JSON解析后放入数组

 

@interface JsonViewController : UITableViewController {
	NSArray *array;
}
@property(nonatomic, retain) NSArray *array;
@end

 

看一下实现文件

 

@implementation JsonViewController
@synthesize array;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"网易新闻";
    array = [[NSArray alloc] initWithArray:[MyDataSource dataSource]];	
}

@end
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics