JSON解析


JSON數據結構解析

    //  路徑
    NSString *path = [[NSBundle mainBundle] pathForResource:@"area" ofType:@"json"];

    //  獲取數據
    NSData *data = [NSData dataWithContentsOfFile:path];

        // 用容器接收Json格式的數據
    NSMutableArray *array = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];

    self.dataArray = [NSMutableArray array];

    for (NSDictionary *oneDic in array) {

//        NSArray *cityArray = oneDic[@"cityList"];
//        
//        [self.dataDic setObject:cityArray forKey:oneDic[@"province"]];

        CityModel *model  = [[CityModel alloc] init];
        [model setValuesForKeysWithDictionary:oneDic];

        [self.dataArray addObject:model];

        [model release];

    }
發佈了32 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章