我正在将 HTML 内容(具有项目符号等特殊字符)插入 SQLite 数据库。
当我尝试在视图上获取内容时,它没有正确显示特殊字符。它向我显示垃圾文本。
如何确保我在数据库中插入的任何文本都正确显示在视图中。
谢谢!
我的插入代码:
// 这个查询方法实现在不同的文件中
- (NSArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args {
sqlite3_stmt *sqlStmt;
if (![self prepareSql:sql inStatament:(&sqlStmt)])
return nil;
int i = 0;
int queryParamCount = sqlite3_bind_parameter_count(sqlStmt);
while (i++ < queryParamCount)
[self bindObject:[args objectAtIndex:(i - 1)] toColumn:i inStatament:sqlStmt];
NSMutableArray *arrayList = [[NSMutableArray alloc] init]; // By Devang
int columnCount = sqlite3_column_count(sqlStmt);
while ([self hasData:sqlStmt]) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for (i = 0; i < columnCount; ++i) {
id columnName = [self columnName:sqlStmt columnIndex:i];
id columnData = [self columnData:sqlStmt columnIndex:i];
[dictionary setObject:columnData forKey:columnName];
}
[arrayList addObject:dictionary];
//[arrayList addObject:[dictionary autorelease]];
}
sqlite3_finalize(sqlStmt);
return arrayList;
}
// 现在通过 make 对象为这个文件调用这个方法
NSString *inserQuery =[NSString stringWithFormat:@"insert into feedtest (title,summary,image,id) values ('%@','%@','%@',%d)",cell.textLabel.text,source,returnURL,indexPath.row];
NSLog(@"query - %@",inserQuery);
[database executeQuery:inserQuery];
// 取回数据
NSString *sd=[NSString stringWithFormat:@"Select title,summary from feedtest"];
NSMutableArray *p=[[NSMutableArray alloc]init];
p=[[database executeQuery:sd ] mutableCopy];
[database close];
NSString *titleHTML = [[p objectAtIndex:i]valueForKey:@"title"];
NSString *postHTML =[[p objectAtIndex:i]valueForKey:@"summary"];
NSLog(@"%@",titleHTML);
NSLog(@"%@",postHTML);