0
의있는 NSArray에서 요소를 얻는 방법이 NSLog 내 NSArray를내가 NSDictionary에
[{"id":16,"venueId":16,"street":"171 - 3401 Dufferin St","city":"Toronto","zipcode":"M6A 2T9","province":"ON","country":"Canada"}]
의있는 NSArray에서 요소를 얻는 방법이 NSLog 내 NSArray를내가 NSDictionary에
[{"id":16,"venueId":16,"street":"171 - 3401 Dufferin St","city":"Toronto","zipcode":"M6A 2T9","province":"ON","country":"Canada"}]
NSDictionary *dict = [myarray objectAtIndex:i]
//myarray is your array of dictionary
//if the array has just one element like in your example, i will be 0
NSNumber *venueId = [dict objectForKey:@"venueId"];
하다 마침내 나는 솔루션
NSError *error;
NSArray* jsonArray = [NSJSONSerialization JSONObjectWithData:[[venue objectForKey:@"address"] dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error] ;
NSDictionary *dict = [jsonArray objectAtIndex:0];
//myarray is your array of dictionary
NSString *street = [dict objectForKey:@"street"];
NSLog(@"street: %@", street);
주를 발견 : 나는 데이터 유형을 확인하는 코드 아래 사용 유효한 종류의 클래스를 반환하는지 확인하십시오.
if ([[venue objectForKey:@"address"] isKindOfClass:[NSArray class]]) {
NSLog(@"%@", @"It is NSArray");
} else if ([[venue objectForKey:@"address"] isKindOfClass:[NSString class]]) {
NSLog(@"%@", @"It is NSString");
}
그것은 오류가 발생합니다 - [__ NSCFString objectAtIndex :] : 인식 할 수없는 선택 예를 – virengujariya
감사 Hetal로 전송. NSJSONSerialization을 사용하여 데이터에 NSArray 유형이 있는지 확인했습니다. 나는 대답을 올렸다. – virengujariya