"title"값을 검색해야하는 다중 JSON 객체가 있습니다. 나는 각각의 "제목"값을 가져 오는 데 성공하지만,이 제목 값을 모두 NSMutableArray
에 어떻게 넣을 수 있는지 잘 모르겠습니다. UITableView
을 나중에 채울 수 있습니다.Xcode에서 검색된 JSON 값의 배열을 만드는 방법
현재 storyTitle (NSString
)은 여러 개의 다른 문자열을 반환하지만 모두 별도입니다. 예를 들어, 콘솔은 다음을 반환합니다.
2013-03-30 21:39:30.416 Appv0.1[32742:11303] (
"Boys\U2019 lacrosse display drive at Watsonville Jamboree"
)
2013-03-30 21:39:31.799 Appv0.1[32742:11303] (
"Volleyball teams currently undefeated midway through season"
)
2013-03-30 21:39:32.093 Appv0.1[32742:11303] (
"Wrestling season ends with a CCS victory and 2 state berths"
)
이러한 문자열을 배열에 결합하는 방법은 무엇입니까? 미리 감사드립니다! 어떤 도움을 주시면 감사하겠습니다.
NSDictionary *res = [NSJSONSerialization JSONObjectWithData: returnData options:NSJSONReadingMutableLeaves error:&myError];
storyList = [NSMutableArray alloc];
storyTitle = [res objectForKey:@"title"];
//create array of storyTitles
NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle];
//not sure how to do this array part
storyList = [NSMutableArray arrayWithObjects:story1,nil];
편집 : 내가 할 경우
for(int i = 0; i < 5; i++){
storyTitle = [res objectForKey:@"title"];
NSString * story1 = [NSString stringWithFormat:@"%@", storyTitle];
[self.storyList addObject:story1];
}
콘솔
array: (
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",
"Boys\U2019 lacrosse display drive at Watsonville Jamboree",)
가 어떻게 배열이 3 개 별도의 이야기를 만들 수 있죠 반환?
광기가 계속해서 똑같은 일을 반복하고 있으며 다른 결과를 기대하고 있다는 말이 있습니다. 루프를 할 때'storyTitle'을 위해 무엇을 선택 할지를 바꾸기 위해 어디에서나'i'를 사용하지 않습니다 (루프 반복마다 변경되는 것도 없습니다). –