0

オブジェクトarchiveUnarchive含むデータが必要です。NSDictionaryデータ中にクラッシュが見られUnarchivingます。以下のコードとエラーを見つけてください。

記録:

 NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mydictobject];

アーカイブ解除:

 NSData *Objdata = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2)   
                    length:sqlite3_column_bytes(statement, 2)];
 NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] 
                                   initForReadingWithData:Objdata];
 NSDictionary *dict = [NSDictionary dictionaryWithDictionary:
                       [NSKeyedUnarchiver unarchiveObjectWithData:Objdata]];
[dict objectForKey:@"key1"];

エラー:

* キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '-[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0xfffffff8, 0xffffffc7, 0xf, 0x1, 0x2, 0x0, 0x0, 0x0)' * * First throw call stack: (0x222b012 0x194e7e 0x222adeb 0xe78c90 0xe7f2 0x3c11 0x19256 0x43f8d5 0x43fb3d 0xe46e83 0x21ea376 0x21e9e06 0x21d1a82 0x21d0f44 0x21d0e1b 0x21857e3 0x2185668 0x39065c 0x2612 0x2545 0x1) libc++abi.dylib: 例外をスローして呼び出された終了

ありがとう。

4

1 に答える 1

0
// To read data do following
-(void) readAnimalsFromDatabase {

    // Setup the database object
    sqlite3 *database;

    // Init the animals Array
    dataArray = [[NSMutableArray alloc] init];

    // Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        // Setup the SQL Statement and compile it for faster access
        const char *sqlStatement = "select * from anyTable";
        sqlite3_stmt *compiledStatement;
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            // Loop through the results and add them to the feeds array
            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                // Read the data from the result row
                NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
                NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

                NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:aName, @"name", aDescription, @"description", aImageUrl, @"imageURL", nil];

                // Add the animal object to the animals Array
                [dataArray addObject:dict];

            }
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }
    sqlite3_close(database);


    // Archive NSArray to NSData
    NSData *archiveData = [NSKeyedArchiver archivedDataWithRootObject:dataArray];

    // UnArchive NSData to NSDictionary
    NSArray *array = [NSArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
    NSLog(@"%@",array);
}
于 2013-03-22T11:35:49.637 に答える