【发布时间】:2012-11-30 13:09:11
【问题描述】:
我正在将 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);
【问题讨论】:
-
请发布您的 INSERTION 和 SELECTION 代码
-
当你 NSLog(@"query - %@",inserQuery);您在控制台上看到 HTML 字符吗?我猜你在解析从网络接收到的数据时删除了 HTML
-
是的,垃圾文本显示在控制台中
标签: iphone objective-c ios cocoa-touch sqlite