我正在創建使用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