首页 > Web开发 > 详细

JSON 数据的 JSONKit 解析

时间:2015-07-20 19:30:55      阅读:325      评论:0      收藏:0      [点我收藏+]
@property (nonatomic, strong) NSMutableArray *JSONArray;

懒加载

- (NSMutableArray *)JSONArray
{
    if (_JSONArray == nil) {
        self.JSONArray = [NSMutableArray array];
    }
    return _JSONArray;
}
- (IBAction)JSONKitButtonDidClicked:(UIButton *)sender {
    // 1、拿到 json 文件的路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"student" ofType:@"json"];

    // 2、根据路径获取文件内容为 NSData 对象
    NSData *data = [NSData dataWithContentsOfFile:path];

    // 3、解析为数组
    NSArray *array = [data objectFromJSONData];


    for (NSDictionary *dict in array) {
        StudentModal *modal = [StudentModal new];
        [modal setValuesForKeysWithDictionary:dict];
        [self.JSONArray addObject:modal];
    }

    for (StudentModal *modal in self.JSONArray) {
        NSLog(@"JSONArray = %@, %ld, %@", modal.name, modal.number, modal.hobby);
    }

    [self.JSONArray removeAllObjects];

    // 把OC里面的数据类型转化成 json 串
    NSString *yadong;
    [yadong JSONString];

    NSArray *testArray = @[@"wewe", @"www", @"qq"];

    NSString *result = [testArray JSONString];
    NSLog(@"result = %@", result);

}

版权声明:本文为outlan原创文章,未经博主允许不得转载。

JSON 数据的 JSONKit 解析

原文:http://blog.csdn.net/yadong_zhao/article/details/46971487

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!