Reputation: 1535
I am trying to fetch object from following from JSON file but getting error.I want to display this data to tbaleview.
OrganizationList = ( ( 17, TGB, Ahmedabad, "SG Highway", Dover, "Georgia", 388306, 12345, "www.abc.com", "37.23909", "-122.34567", "Dec 6, 2013 5:11:15 PM" ) ); isError = 0; message = "Organization List is...";
I want to fetch "TGB" from this.... I have tried this
for(int i=0;i<[tempDataArray count];i++){
[temp addObject:[tempDataArray objectAtIndex:i]];
NSLog(@"temp%@",temp);
[searchArray addObject:[temp objectAtIndex:0]];
NSLog(@"searcharray with name%@",searchArray);
NSLog(@"name%@",[searchArray objectAtIndex:1]);
}
Here is tempArray...
(
(
17,
TGB,
Ahmedabad,
"SG Highway",
Dover,
"Georgia",
388306,
12345,
"www.abc.com",
"37.23909",
"-122.34567",
"Dec 6, 2013 5:11:15 PM"
)
)
but this is giving me error index out of bound at index 1.
Upvotes: 0
Views: 114
Reputation: 776
tempArray is not just an array, means not a single dimension array, it's two-dimensional array.
for(int i=0;i<[tempDataArray count];i++){
NSArray *secondArray = [tempArray objectAtIndex:i];
[temp addObject:secondArray];
NSLog(@"temp%@",temp);
for(int j=0; j < [secondArray count]; j++) {
[searchArray addObject:[secondArray objectAtIndex:j]];
}
NSLog(@"searcharray with name%@",searchArray);
NSLog(@"name%@",[searchArray objectAtIndex:1]);
}
Upvotes: 3
Reputation: 859
Try the following,
for (NSDictionary *dictionary in tempDataArray)
{
[yourTempArry addObject: dictionary];
}
for (NSString * sTemp in yourTempArry)
{
NSRange titleResultsRange = [sTemp.LocationName rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[searchArray addObject:sTemp];
}
Upvotes: 0