我正在尝试从JSON文件中获取以下对象,但是收到错误。我想将此数据显示给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...";
我想从此获取“TGB”.... 我试过这个
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]);
}
这是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.
答案 0 :(得分:3)
tempArray不仅仅是一个数组,意味着不是单维数组,而是二维数组。
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]);
}
答案 1 :(得分:0)
尝试以下方法,
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];
}