2012-03-28 6 views
1

Json Datas를 sqlite 데이터베이스에 삽입하려고합니다. 다른 클래스의 데이터가 있는데 사전 (responce.item)에 있지만 데이터베이스에 삽입 할 수 없습니다. 이렇게 오류가 발생했습니다 : 인식 할 수없는 선택기가 인스턴스로 전송되었습니다. 이 문제를 어떻게 해결할 수 있습니까? 내 방법은 아래 있습니다. 답장을 보내 주셔서 감사합니다.- [__ NSArrayM objectForKey :] : 인식 할 수없는 선택기가 인스턴스 c에 전송되었습니다.

편집 코드 :

-(void)processDoneWithRequestName:(NSString*)tagName{ 

sqlite3_stmt *stmt=nil; 
sqlite3 *cruddb; 

const char *sql = "INSERT INTO LabUpdate (IsSuccess, ProducerId, Latitude, Longitude, Altitude, Slope, SampleDate, PackageNo, Status, Description) VALUES (?,?,?,?,?,?,?,?,?,?)";    

//NSArray *pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
NSString *[email protected]"/Users/ds/Desktop/SqliteTest/SqliteTest"; 
NSString *cruddatabase=[doumentDirectoryPath stringByAppendingPathComponent:@"SqliteTestDb.sqlite"]; 

if ([tagName isEqualToString:Logins]) { 

    int keys = [[response.item objectForKey:@"Lipton"] count]; 
    NSLog(@"count %i",keys); 
    for (int i=0; i<keys; i++) 
    { 

     NSString *str1 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"IsSuccess"]; 
     NSString *str2 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"ProducerId"]; 
     NSString *str3 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Latitude"]; 
     NSString *str4 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Longitude"]; 
     NSString *str5 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Altitude"]; 
     NSString *str6 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Slope"]; 
     NSString *str7 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"SampleDate"]; 
     NSString *str8 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"PackageNo"]; 
     NSString *str9 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Status"]; 
     NSString *str10 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Description"]; 
     NSLog(@"str1 %@",str1); 
     NSLog(@"str2 %@",str2); 
     NSLog(@"str3 %@",str3); 
     NSLog(@"str4 %@",str4); 
     NSLog(@"str5 %@",str5); 
     NSLog(@"str6 %@",str6); 
     NSLog(@"str7 %@",str7); 
     NSLog(@"str8 %@",str8); 
     NSLog(@"str9 %@",str9); 
     NSLog(@"str10 %@",str10); 




     sqlite3_open([cruddatabase UTF8String], &cruddb); 
     sqlite3_prepare_v2(cruddb, sql, 1, &stmt, NULL); 
     sqlite3_bind_int(stmt, 1, [str1 integerValue]); 
     sqlite3_bind_int(stmt, 2, [str2 integerValue]); 
     sqlite3_bind_double(stmt, 3, [str3 floatValue]); 
     sqlite3_bind_double(stmt, 4, [str4 floatValue]); 
     sqlite3_bind_double(stmt, 5, [str5 floatValue]); 
     sqlite3_bind_double(stmt, 6, [str6 floatValue]); 
     sqlite3_bind_text(stmt, 7, [str7 UTF8String], -1, SQLITE_TRANSIENT); 
     sqlite3_bind_int(stmt, 8, [str8 integerValue]); 
     sqlite3_bind_int(stmt, 9, [str9 integerValue]); 
     sqlite3_bind_text(stmt, 10, [str10 UTF8String], -1, SQLITE_TRANSIENT); 


     sqlite3_step(stmt); 
     sqlite3_finalize(stmt); 
     sqlite3_close(cruddb); 



    } 



} 

}는

+0

어떤 라인에 오류가 있습니까? –

+0

정확히 어떤 오류가 나옵니까. 전체 오류를 게시하십시오. – Bharathi

+0

JSON 페이로드의 예를 게시 할 수 있습니까? – Alladinian

답변

4

즉 오류 객체가 NSArrayNSDictionary 아닌 것을 의미한다. -objectAtIndex:을 사용하여 사전 오브젝트에 액세스 할 수 있습니다.

편집 : 이것에

int keys = [[response.item objectForKey:@"Lipton"] count]; 

:

int keys = [[[response.item objectForKey:@"Lipton"] objectAtIndex:0] count]; 

나 :

int keys = [[[response.item objectAtIndex:0] objectForKey:@"Lipton"] count]; 

그것은 당신이 제공 한 정보에서 이야기하지만,이 라인을 변경하려고하기 어렵다 내가 말했듯이, 나는 더 많은 정보없이 결정적인 대답을 줄 수는 없다.

+0

ok objectAtIndex를 사용하지만 키 수가 1이므로 한 번만 입력 할 수 있습니다. 내가 지금 무엇을 할 수 있을까? –

+0

내 대답에 편집 참조하십시오. – edc1591

+0

Ok 답장을 보내 주셔서 감사합니다.하지만 위의 코드를 호출하는 RequestResponce 클래스에서 충돌이 발생합니다. [delegate processDoneWithRequestName : headerTag]; 이 문제를 어떻게 해결할 수 있습니까? –

관련 문제