2012-03-28 13 views
1

sqliteデータベースにJson Datasを挿入しようとしています。別のクラスのデータがあり、辞書(responce.item)にありますが、データベースに挿入できません。私はこのようなエラーを受け取りました:認識できないセレクタがインスタンスに送られました。どうすればこの問題を解決できますか?私の方法は以下の通りです。お返事をありがとうございます。- [__ NSArrayM objectForKey:]:インスタンスに送信された認識できないセレクタObjective cのエラー

編集されたコード:

-(void)processDoneWithRequestName:(NSString*)tagName{ 

sqlite3_stmt *stmt=nil; 
sqlite3 *cruddb; 

const char *sql = "INSERT INTO LabUpdate (IsSuccess, ProducerId, Latitude, Longitude, Altitude, Slope, SampleDate, PackageNo, Status, Description) VALUES (?,?,?,?,?,?,?,?,?,?)";    

//NSArray *pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
NSString *[email protected]"/Users/ds/Desktop/SqliteTest/SqliteTest"; 
NSString *cruddatabase=[doumentDirectoryPath stringByAppendingPathComponent:@"SqliteTestDb.sqlite"]; 

if ([tagName isEqualToString:Logins]) { 

    int keys = [[response.item objectForKey:@"Lipton"] count]; 
    NSLog(@"count %i",keys); 
    for (int i=0; i<keys; i++) 
    { 

     NSString *str1 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"IsSuccess"]; 
     NSString *str2 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"ProducerId"]; 
     NSString *str3 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Latitude"]; 
     NSString *str4 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Longitude"]; 
     NSString *str5 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Altitude"]; 
     NSString *str6 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Slope"]; 
     NSString *str7 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"SampleDate"]; 
     NSString *str8 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"PackageNo"]; 
     NSString *str9 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Status"]; 
     NSString *str10 =[[[response.item objectForKey:@"Lipton"] objectAtIndex:i]objectForKey:@"Description"]; 
     NSLog(@"str1 %@",str1); 
     NSLog(@"str2 %@",str2); 
     NSLog(@"str3 %@",str3); 
     NSLog(@"str4 %@",str4); 
     NSLog(@"str5 %@",str5); 
     NSLog(@"str6 %@",str6); 
     NSLog(@"str7 %@",str7); 
     NSLog(@"str8 %@",str8); 
     NSLog(@"str9 %@",str9); 
     NSLog(@"str10 %@",str10); 




     sqlite3_open([cruddatabase UTF8String], &cruddb); 
     sqlite3_prepare_v2(cruddb, sql, 1, &stmt, NULL); 
     sqlite3_bind_int(stmt, 1, [str1 integerValue]); 
     sqlite3_bind_int(stmt, 2, [str2 integerValue]); 
     sqlite3_bind_double(stmt, 3, [str3 floatValue]); 
     sqlite3_bind_double(stmt, 4, [str4 floatValue]); 
     sqlite3_bind_double(stmt, 5, [str5 floatValue]); 
     sqlite3_bind_double(stmt, 6, [str6 floatValue]); 
     sqlite3_bind_text(stmt, 7, [str7 UTF8String], -1, SQLITE_TRANSIENT); 
     sqlite3_bind_int(stmt, 8, [str8 integerValue]); 
     sqlite3_bind_int(stmt, 9, [str9 integerValue]); 
     sqlite3_bind_text(stmt, 10, [str10 UTF8String], -1, SQLITE_TRANSIENT); 


     sqlite3_step(stmt); 
     sqlite3_finalize(stmt); 
     sqlite3_close(cruddb); 



    } 



} 

は}

+0

どのラインにエラーがありますか? –

+0

正確にどのエラーになっていますか?エラー全体を投稿してください。 – Bharathi

+0

JSONペイロードの例を投稿できますか? – Alladinian

答えて

4

というエラーは、オブジェクトがNSArrayないNSDictionaryであることを意味します。 -objectAtIndex:を使用して辞書オブジェクトにアクセスできます。

EDIT:これまで

int keys = [[response.item objectForKey:@"Lipton"] count]; 

int keys = [[[response.item objectForKey:@"Lipton"] objectAtIndex:0] count]; 

か:

int keys = [[[response.item objectAtIndex:0] objectForKey:@"Lipton"] count]; 

それはあなたが提供した情報から言うが、この行を変更してみてくださいするのは難しいです私が言ったように、私はより多くの情報なしに決定的な答えを出すことはできません。

+0

私はobjectAtIndexを使用しますが、キーの数は1ですので、1回しか入力できません。私は今何をすることができますか? –

+0

私の答えに編集を参照してください。 – edc1591

+0

私は既にあなたの返信のためにこの問題を解決しましたが、私は上記のコード[代理人processDoneWithRequestName:headerTag]を呼び出す私のRequestResponceクラスでクラッシュするようになりました。どうすればこの問題を解決できますか? –

関連する問題