Ich versuche, Json-Daten in die SQLite-Datenbank einzufügen. Ich habe Daten von einer anderen Klasse und sie sind in einem Wörterbuch (responce.item), aber ich kann nicht in die Datenbank einfügen. Ich habe einen Fehler wie folgt erhalten: unerkannter Selektor, der an Instanz gesendet wurde. Wie kann ich dieses Problem lösen? Meine Methode ist unten. Danke für deine Antwort.- [__ NSArrayM objectForKey:]: unerkannter Selektor an Instanz gesendet Fehler in Objective c
editierten Code:
-(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);
}
}
}
In welcher Zeile ist der Fehler aufgetreten? –
Welcher Fehler genau wird erhalten. Veröffentlichen Sie den gesamten Fehler. – Bharathi
Können Sie ein Beispiel für Ihre JSON-Nutzdaten veröffentlichen? – Alladinian