Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c -[\uu NSArrayM objectForKey:]:在目标c中发送到实例的选择器出现无法识别的错误_Objective C_Ios_Xcode_Json_Sqlite - Fatal编程技术网

Objective c -[\uu NSArrayM objectForKey:]:在目标c中发送到实例的选择器出现无法识别的错误

Objective c -[\uu NSArrayM objectForKey:]:在目标c中发送到实例的选择器出现无法识别的错误,objective-c,ios,xcode,json,sqlite,Objective C,Ios,Xcode,Json,Sqlite,我尝试将Json数据插入sqlite数据库。我从另一个类获取了数据,它们在字典(response.item)中,但我无法插入到数据库中。我得到一个类似这样的错误:无法识别的选择器被发送到实例。我怎样才能解决这个问题?我的方法如下。谢谢你的回复 编辑的代码: -(void)processDoneWithRequestName:(NSString*)tagName{ sqlite3_stmt *stmt=nil; sqlite3 *cruddb; const char *sql = "INSER

我尝试将Json数据插入sqlite数据库。我从另一个类获取了数据,它们在字典(response.item)中,但我无法插入到数据库中。我得到一个类似这样的错误:无法识别的选择器被发送到实例。我怎样才能解决这个问题?我的方法如下。谢谢你的回复

编辑的代码:

-(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 *doumentDirectoryPath=@"/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); 



    }



}
-(void)processDoneWithRequestName:(NSString*)标记名{
sqlite3_stmt*stmt=nil;
sqlite3*cruddb;
const char*sql=“插入LabUpdate(IsSuccess、ProducerId、纬度、经度、海拔、坡度、采样日期、包装、状态、说明)值(?,,,,,,,,,,,,,,?)”;
//NSArray*pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*doumentDirectoryPath=@“/Users/ds/Desktop/SqliteTest/SqliteTest”;
NSString*cruddatabase=[doumentDirectoryPath stringByAppendingPathComponent:@“SqliteTestDb.sqlite”];
if([标记名IsequalString:登录]){
int keys=[[response.item objectForKey:@“Lipton”]count];
NSLog(@“计数%i”,键);

对于(int i=0;i,该错误表示对象是
NSArray
而不是
NSDictionary
。您可以使用
-objectAtIndex:
访问dictionary对象

编辑:根据您提供的信息很难判断,但请尝试更改此行:

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

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


正如我所说,如果没有更多信息,我无法给出决定性的答案。

该错误意味着对象是
NSArray
而不是
NSDictionary
。您可以使用
-objectAtIndex:
访问dictionary对象

编辑:根据您提供的信息很难判断,但请尝试更改此行:

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

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



正如我所说,如果没有更多的信息,我无法给出决定性的答案。

到底是哪个错误。发布整个错误。你能发布一个JSON负载的示例吗?好的,我用-objectAtIndex解决了这个问题:但它只进入了一次for循环。数据库文件中没有记录。:S我该怎么做?我现在编辑了代码,可以访问我会在字典中找到值,但在数据库表中看不到。我如何解决?到底是哪个错误。发布整个错误。你能发布一个JSON负载的示例吗?好的,我用-objectAtIndex解决了这个问题:但它只进入了一次for循环。数据库文件中没有记录。:S我该怎么做?我编辑了代码,现在可以访问我会在字典中输入值,但在数据库表中看不到。我如何解决?好的,我使用objectAtIndex,但键数为1,所以我只能输入1次。现在我能做什么?好的,我已经解决了这个问题,感谢您的回复,但现在它在我的RequestResponse类中崩溃,我调用了上面的代码[delegate processDoneWithRequestName:headerTag];如何解决此问题?您的委托是否实现了该方法?该方法在哪个类中,以及
委托在哪个类中?错误:在-[ViewController processDoneWithRequestName:]中断言失败,/Users/ds/Desktop/SqliteTest/SqliteTest/ViewController.m:186好的,我使用objectAtIndex,但是键数为1,所以我只能输入1次。现在我能做什么?好的,我已经解决了这个问题,谢谢你的回答,但是现在它在我的requestresponse类中崩溃了,我调用了上面的代码[delegate processDoneWithRequestName:headerTag];如何解决此问题?您的委托是否实现了该方法?该方法在哪个类中,以及该委托在哪个类中?错误:在-[ViewController processDoneWithRequestName:],/Users/ds/Desktop/SqliteTest/SqliteTest/ViewController.m:186中断言失败