내 json 파일에 title
, subtitle
및 url
이 있습니다.NSJSON 배열 정렬이 올바르게 작동하지 않습니다.
title
을 알파벳 순으로 정렬하지만 url
은 title
으로 정렬되지 않으며 이유를 모르겠습니다.
이 내가 무슨 짓을했는지 있습니다 :
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSArray *arrayOfItems = [allDataDictionary objectForKey:@"items"];
for (NSDictionary *diction in arrayOfItems) {
NSString *titles = [diction objectForKey:@"title"];
NSString *station = [diction objectForKey:@"url"];
[jsonArray addObject:titles];
[jsonStations addObject:station];
// SORT JSON
NSArray *sortedArray;
sortedArray = [jsonArray sortedArrayUsingComparator:^NSComparisonResult(NSString *title1, NSString *title2)
{
if ([title1 compare:title2] > 0)
return NSOrderedDescending;
else
return NSOrderedAscending;
}];
[jsonArray setArray:sortedArray];
는 나는있는 tableView의 첫 번째 항목을 누를 때 나는 총 diffrent title
에서 url
를 얻을 수. title
이 tableView의 url
과 일치하도록하려면 어떻게해야합니까?
그래서 당신은'jsonStations' 배열이 자동적으로도 정렬 할 것으로 예상 할 물건을 정리할
희망? –
아니요 ..하지만 json 파일의 동일한 개체 아래에 있기 때문에 제목을 따르는 URL이 예상됩니다.하지만 URL을 정렬해도 제목에 맞지 않습니다. [iOS6 JSON 개체 정렬] 가능한 복제본 –
http://stackoverflow.com/questions/16418746/ios6-sort-json-objects) –