我试图用这两种方法将数据从json插入到sqlite3但是它给了我异常 - [NSDecimalNumber UTF8String]:发送到实例的无法识别的选择器'请帮助我,我是ios的新手..
-(void)insertintoDatabase:(NSMutableArray *)allCatData
{
for (int i=0;i<[allCatData count] ;i++)
{
CategoryData *catData=[allCatData objectAtIndex:i];
appdelegate.categoryString=catData.categoryname;
NSLog(@"array size :%d",[catData.imageArraya count]);
for (int j=0; j<[catData.imageArraya count]; j++)
{
imageconvert *convertedData=[catData.imageArraya objectAtIndex:j];
NSError* error = nil;
NSData* thumbData = [NSData dataWithContentsOfURL: [NSURL URLWithString:[convertedData.thumbimage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] options:NSDataReadingUncached error:&error];
// NSLog(@"aaaaa %@",[convertedData.thumbimage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
//NSLog(@"aaadata %@",thumbData);
NSData* imageData = [NSData dataWithContentsOfURL: [NSURL URLWithString:[convertedData.mainimage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] options:NSDataReadingUncached error:&error];
// NSLog(@"bbbbb %@",[convertedData.mainimage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
// NSLog(@"bbbdata %@",imageData);
if (error)
{
NSLog(@"%@", [error localizedDescription]);
}
else
{
//insert date modified and categorynm into database
[self SaveThumbDatatosql:thumbData withImageData:imageData WithCatName:catData.categoryname withImagename:convertedData.imageName withLastmodified:convertedData.lastmodified];
}
}
}
}
- (void) SaveThumbDatatosql:(NSData*) thumbData withImageData:(NSData*) imageData WithCatName:(NSString*) CategoryName withImagename:(NSString*) ImageName withLastmodified:(NSString*) Lastmodified
{
// NSLog(@"thumbData:%@ imageData:%@ CategoryName:%@ ImageName:%@ Lastmodified:%@",thumbData,imageData,CategoryName,ImageName,Lastmodified);
sqlite3 *database;
if (sqlite3_open([appdelegate.databasePath UTF8String], &database) == SQLITE_OK)
{
sqlite3_stmt *statement;
const char* sqliteQuery = "INSERT INTO CategoryTable (ThumbImagePath,ImagePath,Categoryname,Imagename,Lastmodified) VALUES (?,?,?,?,?)";
if (sqlite3_prepare_v2(database, sqliteQuery, -1, &statement, NULL) == SQLITE_OK)
{
NSLog(@"CategoryName:%@ ImageName:%@ Lastmodified:%@",CategoryName,ImageName,Lastmodified);
sqlite3_bind_blob(statement, 1, [thumbData bytes], [thumbData length], SQLITE_STATIC);
sqlite3_bind_blob(statement, 2, [imageData bytes], [imageData length], SQLITE_STATIC);
sqlite3_bind_text(statement, 3, [CategoryName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 4, [ImageName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 5, [Lastmodified UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_step(statement);
sqlite3_finalize(statement);
NSLog(@"inserted ");
}
else
{
NSAssert1(0, @"error:'%s'", sqlite3_errmsg(database));
NSLog(@"not inserted ");
}
sqlite3_close(database);
}
}
答案 0 :(得分:1)
看起来Lastmodified
是NSDecimalNumber
,您可以调用选择器UTF8String
。