我正在创建使用Sqlite DB的iOS
应用程序。 我已经创建Table
由于:如何从iOS中的Sqlite中将NSdata检索到NSdictionary中
const char *sql_stmt = "CREATE TABLE IF NOT EXISTS ORDERTABLE (ID INTEGER PRIMARY KEY AUTOINCREMENT, ITEMDESC TEXT)";
,然后我要插入self.selectedItemsDictnory解释成ItemDESC 我一样插入:
NSData *data = [NSJSONSerialization dataWithJSONObject:self.selectedItemsDictnory options:NSJSONWritingPrettyPrinted error:nil];
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO ORDERTABLE(ITEMDESC)VALUES(\"%@\");",data];
高达这一点,已成功完成。
现在我已经找回本词典在相同的格式
我在做什么是:
if (sqlite3_open(dbpath, &orderDB) == SQLITE_OK)
{
const char* sqlStatement = [[NSString stringWithFormat:@"SELECT * FROM ORDERTABLE WHERE (ID = '%d')",self.orderSelected]cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt* statement;
if (sqlite3_prepare_v2(orderDB, sqlStatement, -1, &statement, NULL) == SQLITE_OK) {
if(sqlite3_step(statement) == SQLITE_ROW)
{
NSData *retData = (__bridge NSData*) sqlite3_column_value(statement, 1);
NSDictionary *jsonObject=[NSJSONSerialization
JSONObjectWithData:retData
options:NSJSONReadingMutableLeaves
error:nil];
NSLog(@"jsonObject is %@",jsonObject);
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfData:retData];
NSLog(@"dic is %@",dic);
}
}
sqlite3_finalize(statement);
sqlite3_close(orderDB);
}
但我越来越坏过剩例外。 请帮我出来检索数据
你能指出确切的线路,你在哪里得到异常? – 2013-04-24 06:34:03
嗨,我收到异常在 NSDictionary * jsonObject = [NSJSONSerialization JSONObjectWithData:retData options:NSJSONReadingMutableLeaves error:nil]; – Sulabh 2013-04-24 06:36:40
是retData是否为零? – karthik 2013-04-24 06:40:14