저는 iOS의 초보자이며 약간의 문제가 있습니다. 인덱스 i와 키 x에 대해 JSONObject에서 데이터를 가져 오는 방법을 알지 못합니다.(iOS) 배열에있는 json의 데이터를 추가하십시오.
그냥 아래
-(NSMutableArray*)getAll{
NSMutableArray* liste;
dispatch_queue_t downloadQueue = dispatch_queue_create("Get All Offers", NULL);
dispatch_async(downloadQueue, ^{
NSData *result = [self executePostCall];
dispatch_async(dispatch_get_main_queue(), ^{
id strResult=nil;
NSError* error;
strResult = [NSJSONSerialization JSONObjectWithData:result options:0 error:&error];
for(int cpt=0; cpt>[strResult count];cpt++)
{
[liste addObject:[NSMutableArray new]];
// ERREUR ICI !!!!!!!!!
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"titre"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"srcImage"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"date"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"prix"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"ville"]]];
[[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"categorie"]]];
}
});
});
NSLog(@"liste: %@",liste);
return liste;
}
내가 라인 CPT에서 키 (예 : "역가")으로 객체를 얻기 위해 시도 내 코드가있다. 도와 줄수있으세요 ?
나는 문제가 내가 [[liste objectAtIndex:cpt] addObject:[[NSString alloc] initWithFormat:@"%@",[[strResult objectAtIndex:cpt] objectForKey:@"titre"]]];
을하고있을 때이지만 나는 그것을 해결하는 방법을 모른다라고 생각한다.
[self executePostCall]
은 잘 작동하는 또 다른 기능입니다. JSON에 따라 당신의 도움이
JSON 응답과 비슷한 모양을 보여줄 수 있습니까? – Larme
@Larme 코드가 바로 아래에 있습니다. 도움을 주셔서 감사합니다. – ben77650