블로그 이미지
Sunny's

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

'parse'에 해당되는 글 1

  1. 2011.11.06 iOS JSON 멀티항목 Parse
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
posted by Sunny's
prev 1 next