0

I am new to iOS, please help me how can I read a local JSON file using objective-c

SBJSON *parser = [[SBJSON alloc] init];

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"auth_request" ofType:@"json"];


NSError *error = nil;

NSData *JSONData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
NSString *json_string = [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding];



NSArray *statuses = [parser objectWithString:json_string error:nil];



for (NSDictionary *status in statuses) {


    NSLog(@"%@ - %@", [status objectForKey:@"loginId"], [status objectForKey:@"secret"]);
}
Popeye
  • 11,839
  • 9
  • 58
  • 91
user3156748
  • 49
  • 2
  • 4
  • First thing to learn, it doesn't matter that you are using `xcode` you could be doing this in a text editor and it would still be the same. – Popeye Jan 06 '14 at 20:27
  • 2
    `NSArray* statuses = [NSJSONSerialization JSONObjectFromData:JSONData options:0 error:&error];` (where `error` is the usual NSError object). – Hot Licks Jan 06 '14 at 21:06

1 Answers1

-1

Just Add NSArray *tempArray = [json_string JSONVALUE] in the place of NSArray *statuses = [parser objectWithString:json_string error:nil];

Don't forget to import

Sudhir
  • 77
  • 5