//
// main.m
// JSON解析
//
// Created by dllo on 15/11/11.
// Copyright (c) 2015年 dllo. All rights reserved.
//
import
import “Movie.h”
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSURL *url = [NSURL URLWithString:@"http://movieapi.m.damai.cn/Movie/Show/MovieList.aspx?cityId=852&k=&page=1&source=10099&type=2&version=50101"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSArray *movieList = [dic objectForKey:@"movieList"];
NSMutableArray *ourselfMovieList = [NSMutableArray array];
for (NSMutableDictionary *movieDic in movieList) {
//只要有一个moiveDic说明存在一个电影,创建电影对象
Movie *movie = [[Movie alloc]init];
//运用KFC间接链接.会使程序更加简洁,程度代码量也会大大改善
// [movie setValuesForKeysWithDictionary:movieDic];
movie.Id = [movieDic objectForKey:@”Id”];
movie.name = [movieDic objectForKey:@”name”];
movie.mainPerson = [movieDic objectForKey:@”mainPersion”];
movie.diretor = [movieDic objectForKey:@”diretor”];
movie.showTime = [movieDic objectForKey:@”showTime”];
movie.pic = [movieDic objectForKey:@”pic”];
movie.s_pic = [movieDic objectForKey:@”s_pic”];
movie.grade = [movieDic objectForKey:@”grade”];
//将电影对象,放进电影
[ourselfMovieList addObject:movie];
}
//遍历ourselfMovieDic
for (Movie *movieInformation in ourselfMovieList) {
NSLog(@"%@ %@ %@ ", [movieInformation Id], [movieInformation name], [movieInformation showTime]);
}
warning 注意:如果使用KVC时,有何类属性不匹配的Key,那么需要我们进行容错处理.
}
return 0;
}