2011. 11. 6. 02:58
IPhone
- (void)viewDidLoad { [super viewDidLoad]; dispatch_async(kBgQueue, ^{ NSData* data = [NSData dataWithContentsOfURL: kLatestKivaLoansURL]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES]; }); }
- (void)fetchedData:(NSData *)responseData { //parse out the json data NSError* error; NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1 options:kNilOptions error:&error]; NSArray* latestLoans = [json objectForKey:@"loans"]; //2 NSLog(@"loans: %@", latestLoans); //3 }
NSString *country = [loan objectForKey:@"name"] ;
NSString *country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];
JSON Parse 객체는 SBJSON 을 써도 동일하며 멀티 항목인 경우 (NSDictionary*)로 캐스팅 하는거에 참고하세요~ ^^*
출처 : http://www.raywenderlich.com/5492/working-with-json-in-ios-5