數(shù)據(jù)解析實例


#import "Moview.h"

@implementation Moview

//******KVC賦值放崩潰,以及轉(zhuǎn)換大小寫,防止于系統(tǒng)關(guān)鍵字沖突*************

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{

if ([key isEqualToString:@"id"]) {

self.ID =value;

}

}

@end

#import "fiveViewController.h"

#define KCELL @"cell"

#import "Moview.h"

@interface fiveViewController ()

@property(nonatomic,strong)UITableView *tableview;

@property(nonatomic,strong)NSMutableArray *array;

@property(nonatomic,strong)NSMutableArray *movieArray;

@property(nonatomic,strong)NSMutableArray *varietyArray;

- (IBAction)segment:(UISegmentedControl *)sender;

@end

@implementation fiveViewController

-(NSMutableArray *)movieArray{

if (!_movieArray) {

_movieArray =[NSMutableArray array];

}return _movieArray;

}

-(NSMutableArray *)varietyArray{

if (!_varietyArray) {

_varietyArray =[NSMutableArray array];

}return _varietyArray;

}

- (IBAction)segment:(UISegmentedControl *)sender {

if (sender.selectedSegmentIndex ==0) {

self.array =self.movieArray;

}else if (sender.selectedSegmentIndex ==1){

self.array=self.varietyArray;

}

[self.tableview reloadData];

}

-(UITableView *)tableview{

if (!_tableview) {

_tableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

}return _tableview;

}

- (void)viewDidLoad {

[super viewDidLoad];

//? ? UISegmentedControl *segment =[[UISegmentedControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50,? 0, 100, 64)];

//? ? segment.backgroundColor =[UIColor redColor];

[self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:KCELL];

self.tableview.dataSource =self;

self.tableview.delegate=self;

[self.view addSubview:self.tableview];

//? ? [self.view addSubview:segment];

[self startPaser];

self.array =self.movieArray;

NSLog(@"%@",self.array);

// Do any additional setup after loading the view.

}

#pragma mark? ==*********cell************

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

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:KCELL forIndexPath:indexPath];

//cell.textLabel.text =@"sdf";

cell.textLabel.text = [self.array[indexPath.row] title];

return cell;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return self.array.count;

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 2;

}

//開始解析數(shù)據(jù)顯示

-(void)startPaser{

NSString *filepath =[[NSBundle mainBundle]pathForResource:@"movie" ofType:@"txt"];

NSData *data =[NSData dataWithContentsOfFile:filepath];

NSArray *array =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

NSDictionary *hotmoviewdic =array[0];//熱門電影

NSArray *hotmoviewarrat =hotmoviewdic[@"data"];

NSLog(@"%@",hotmoviewarrat);

for (NSDictionary *dic in hotmoviewarrat) {

Moview *movie =[[Moview alloc]init];

[movie setValuesForKeysWithDictionary:dic];

[self.movieArray addObject:movie];

}

//熱門綜藝

NSDictionary *hotvarietydic =array[1];

NSArray *hotvarietyarray=hotvarietydic[@"data"];

for (NSDictionary *dic in hotvarietyarray) {

Moview *movie =[[Moview alloc]init];

[movie setValuesForKeysWithDictionary:dic];

[self.varietyArray addObject:movie];

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌兴枯,老刑警劉巖肺稀,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件登渣,死亡現(xiàn)場離奇詭異贾铝,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)庞钢,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來因谎,“玉大人基括,你說我怎么就攤上這事〔撇恚” “怎么了风皿?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長匠璧。 經(jīng)常有香客問我桐款,道長,這世上最難降的妖魔是什么患朱? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任鲁僚,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘冰沙。我一直安慰自己侨艾,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布拓挥。 她就那樣靜靜地躺著唠梨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪侥啤。 梳的紋絲不亂的頭發(fā)上当叭,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天,我揣著相機(jī)與錄音盖灸,去河邊找鬼蚁鳖。 笑死,一個胖子當(dāng)著我的面吹牛赁炎,可吹牛的內(nèi)容都是我干的醉箕。 我是一名探鬼主播,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼徙垫,長吁一口氣:“原來是場噩夢啊……” “哼讥裤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起姻报,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤己英,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后吴旋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體损肛,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年邮府,在試婚紗的時候發(fā)現(xiàn)自己被綠了荧关。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡褂傀,死狀恐怖忍啤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情仙辟,我是刑警寧澤同波,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站叠国,受9級特大地震影響未檩,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜粟焊,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一冤狡、第九天 我趴在偏房一處隱蔽的房頂上張望孙蒙。 院中可真熱鬧,春花似錦悲雳、人聲如沸挎峦。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽坦胶。三九已至,卻和暖如春晴楔,著一層夾襖步出監(jiān)牢的瞬間顿苇,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工税弃, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留纪岁,地道東北人。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓则果,卻偏偏與公主長得像蜂科,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子短条,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容