数据解析_JSON(初学)

 1 /*
 2     
 3     
 4     //JSON解析  系统自带方式 --
 5     
 6     //1.获取路劲
 7     NSString *fielPath = [[NSBundle mainBundle]pathForResource:@"Student.json" ofType:nil];
 8     
 9     //2.讲该路径下的文件(json)转化成 二进制数据
10     NSData *data = [NSData dataWithContentsOfFile:fielPath];
11     
12     //3.查看文件是什么类型的数据
13     
14     //参数如果是 * ,需要对象本身  ** 代表对象地址 ,向该地址中写入数据
15     NSError *error = nil ;
16     NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
17     
18     if (error) {
19         NSLog(@"%@",error);
20     }
21     
22     //父类指针可以指向子类对象
23 //    NSObject *idd = [[Student alloc]init];
24     
25     self.dataArray = [NSMutableArray array];
26     
27     for (NSDictionary *dic in array) {
28         
29         Student *student = [[Student alloc]initWithDictionary:dic];
30         
31         [self.dataArray addObject:student];
32     }
33     
34     
35     
36     
37  */
38     
39 /*
40     
41     //利用第三方 JSONKit文件
42     
43     NSString *fielPath = [[NSBundle mainBundle]pathForResource:@"Student.json" ofType:nil];
44     
45     //讲JSON转化为NSData二进制数据
46     NSData *data = [NSData dataWithContentsOfFile:fielPath];
47     //利用JSONKit 进行解析
48     NSArray *array = [data objectFromJSONData];
49     
50     
51     self.dataArray = [NSMutableArray array];
52     
53     for (NSDictionary *dic in array) {
54         
55         Student *student = [[Student alloc]initWithDictionary:dic];
56         
57         [self.dataArray addObject:student];
58     }
59     
60     
61   */

 

posted @ 2015-10-14 20:57  YX祥  阅读(151)  评论(0编辑  收藏  举报