本地读取Json失败

来源:互联网 发布:三星s4可以用4g网络吗 编辑:程序博客网 时间:2024/04/30 13:15

直接向读取数组一样的        _AllARY = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Address" ofType:@"plist"]];

失败,则可以

       
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"city" ofType:@"json"];
        NSLog(@"filePath: %@", filePath);
        
        NSData *jsonData = [NSData dataWithContentsOfFile:filePath];
        NSLog(@"jsonData: %@", jsonData);
        
        NSError *error = nil;
        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments|NSJSONReadingMutableLeaves error:&error];
        NSLog(@"jsonDict: %@", jsonDict);
        NSLog(@"error: %@", error);

0 0
原创粉丝点击