2013-12-09 277 views
0

我想從JSON文件中獲取對象但獲取error.I想要將此數據顯示到tbaleview。從JSON獲取對象

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

什麼是'searchArray'的nslog? –

+0

顯示json解析的代碼 –

回答

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]); 
    } 
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]; 
}