Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
如何在没有内存错误的情况下在iOS中解析很长的JSon字符串?_Ios_Objective C_Memory Management_Memory Leaks - Fatal编程技术网

如何在没有内存错误的情况下在iOS中解析很长的JSon字符串?

如何在没有内存错误的情况下在iOS中解析很长的JSon字符串?,ios,objective-c,memory-management,memory-leaks,Ios,Objective C,Memory Management,Memory Leaks,我是iOS新手,我有webservice,我正在尝试下载9000+产品信息,我有一个很长的JSON字符串,所以我在下载产品时收到了这个错误消息 malloc:*mmap(大小=1978368)失败(错误代码=12) 错误:无法分配区域 **在malloc\u error\u break中设置断点以进行调试 我试着下载1000以下的产品信息,效果很好。我想,这是记忆问题 这段代码是我项目的一部分 -(void)parser:(NSXMLParser *)parser didEndElement:(

我是iOS新手,我有webservice,我正在尝试下载9000+产品信息,我有一个很长的JSON字符串,所以我在下载产品时收到了这个错误消息

malloc:*mmap(大小=1978368)失败(错误代码=12) 错误:无法分配区域 **在malloc\u error\u break中设置断点以进行调试

我试着下载1000以下的产品信息,效果很好。我想,这是记忆问题

这段代码是我项目的一部分

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

if (temp!=nil && ![temp isEqual:@""]) {
    //basliklar arrayine ilgili tek haberin basligini aktariyoruz.
    //NSLog(@"TEMP=%@",temp);


    NSData *data = [NSJSONSerialization JSONObjectWithData:[temp dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];



    UrunAdi=[data valueForKey:@"UrunAdi"];
    UrunNo=[data valueForKey:@"UrunNo"];
    Koleksiyon=[data valueForKey:@"Koleksiyon"];
    Kompozisyon=[data valueForKey:@"Kompozisyon"];
    GrM=[data valueForKey:@"GrM"];
    URMID=[data valueForKey:@"URMID"];
    En=[data valueForKey:@"En"];
    IslemTipi=[data valueForKey:@"IslemTipi"];
    Dizim=[data valueForKey:@"Dizim"];
    KarteleKodu=[data valueForKey:@"KarteleKodu"];
    Siklik=[data valueForKey:@"Siklik"];
    Euro=[data valueForKey:@"Euro"];
    Dolar=[data valueForKey:@"Dolar"];
    Sterlin=[data valueForKey:@"Sterlin"];
    TL=[data valueForKey:@"TL"];

    [sharedManager  getNewDBConnection];

    if(![temp isEqualToString:@"false"]){

        sqlite3 *contactDB;


        NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *docsDir = [dirPaths objectAtIndex:0];
        NSString *databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: SQL]];

        NSFileManager *filemgr = [NSFileManager defaultManager];

        if ([filemgr fileExistsAtPath: databasePath ] == YES)
        {
            const char *dbpath = [databasePath UTF8String];

            if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
            {


                NSString *deleteSQL = [NSString stringWithFormat: @"delete from tblKumasBilgi"];

                const char *sql_stmt = [deleteSQL UTF8String];

                if(sqlite3_exec(contactDB, sql_stmt, NULL, NULL, NULL) == SQLITE_OK)
                {
                   // NSLog (@"Delete UserData Succesful");
                }
                else
                {
                    NSLog(@"Delete UserData Fail");
                }
                //sqlite3_close(contactDB);
            }
            else
            {
                NSLog(@"Failed to open database");
            }
        }
    }


    if([temp isEqualToString:@"false"]){

         [SVProgressHUD dismiss];

        NSString *warning = NSLocalizedString(@"Warning",nil);
        NSString *check=NSLocalizedString(@"Check Your User Info",nil);
        NSString *okay=NSLocalizedString(@"Ok", nil);

        UIAlertView *alertViewUser = [[UIAlertView alloc] initWithTitle:warning
                                                            message:check
                                                           delegate:self
                                                  cancelButtonTitle:okay
                                                  otherButtonTitles:nil, nil];

        [alertViewUser show];
        alertViewUser.tag=1;
        flag=NO;

    }
    else{

                sqlite3 *contactDB;

                NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString *docsDir = [dirPaths objectAtIndex:0];
                NSString *databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: SQL]];

                NSFileManager *filemgr = [NSFileManager defaultManager];

    if ([filemgr fileExistsAtPath: databasePath ] == YES)
    {
        const char *dbpath = [databasePath UTF8String];

        if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
        {


            for (int i = 0; i < [UrunNo count]; i++) {



                NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO tblKumasBilgi (UrunAdi,UrunNo,Koleksiyon,Kompozisyon,Grm,URMID,En,IslemTipi,Dizim,KarteleKodu,Siklik,Euro,Dolar,Sterlin,TL) VALUES ('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')", [UrunAdi objectAtIndex:i], [UrunNo objectAtIndex:i], [Koleksiyon objectAtIndex:i], [Kompozisyon objectAtIndex:i], [GrM objectAtIndex:i], [URMID objectAtIndex:i], [En objectAtIndex:i], [IslemTipi objectAtIndex:i],[Dizim objectAtIndex:i],[KarteleKodu objectAtIndex:i], [Siklik objectAtIndex:i],[Euro objectAtIndex:i],[Dolar objectAtIndex:i],[Sterlin objectAtIndex:i], [TL objectAtIndex:i]];

                //NSLog(@"insert =%@",insertSQL);

            const char *sql_stmt = [insertSQL UTF8String];

            if(sqlite3_exec(contactDB, sql_stmt, NULL, NULL, NULL) == SQLITE_OK)
            {
                //NSLog (@"INSERT INTO UserData Succesful");
            }
            else
            {
                NSLog(@"INSERT INTO UserData Fail");
            }

        }
        }
        else
        {
            NSLog(@"Failed to open database");
        }
        //sqlite3_close(contactDB);
    }

        [SVProgressHUD dismiss];
        NSString *warning = NSLocalizedString(@"Warning", nil);
        NSString *dataSuccesful=NSLocalizedString(@"Data Download Succesfully", nil);
        NSString *okay=NSLocalizedString(@"Ok", nil);


        UIAlertView *alertViewDownload = [[UIAlertView alloc] initWithTitle:warning
                                                            message:dataSuccesful
                                                           delegate:self
                                                  cancelButtonTitle:okay
                                                  otherButtonTitles:nil, nil];

        [alertViewDownload show];
        alertViewDownload.tag=2;


        flag=NO;
}


tempElement=@"";
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName{
如果(temp!=nil&&![temp isEqual:@”“])){
//巴西利基尼-阿卡塔里约鲁兹的巴西利基尼·阿卡塔里约鲁兹。
//NSLog(@“TEMP=%@”,TEMP);
NSData*data=[NSJSONSerialization JSONObjectWithData:[temp dataUsingEncoding:NSUTF8StringEncoding]选项:0错误:无];
UrunAdi=[数据值forkey:@“UrunAdi”];
UrunNo=[数据值forkey:@“UrunNo”];
Koleksiyon=[数据值forkey:@“Koleksiyon”];
Kompozisyon=[数据值forkey:@“Kompozisyon”];
GrM=[数据值forkey:@“GrM”];
URMID=[数据值forkey:@“URMID”];
En=[数据值forkey:@“En”];
IslemTipi=[数据值forkey:@“IslemTipi”];
Dizim=[数据值forkey:@“Dizim”];
KarteleKodu=[数据值forkey:@“KarteleKodu”];
Siklik=[数据值forkey:@“Siklik”];
欧元=[数据值forkey:@“欧元];
Dolar=[数据值forkey:@“Dolar”];
Sterlin=[数据值forkey:@“Sterlin”];
TL=[data valueForKey:@“TL”];
[sharedManager getNewDBConnection];
如果(![temp isEqualToString:@“false”]){
sqlite3*contactDB;
NSArray*dirpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString*docsDir=[dirpath objectAtIndex:0];
NSString*databasePath=[[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:SQL]];
NSFileManager*filemgr=[NSFileManager defaultManager];
如果([filemgr fileExistsAtPath:databasePath]==是)
{
const char*dbpath=[databasePath UTF8String];
if(sqlite3\u打开(dbpath和contactDB)==SQLITE\u正常)
{
NSString*deleteSQL=[NSString stringWithFormat:@“从tblKumasBilgi删除”];
常量字符*sql_stmt=[deleteSQL UTF8String];
if(sqlite3_exec(contactDB,sql stmt,NULL,NULL,NULL)==SQLITE_OK)
{
//NSLog(@“删除用户数据成功”);
}
其他的
{
NSLog(@“删除用户数据失败”);
}
//sqlite3_关闭(contactDB);
}
其他的
{
NSLog(@“无法打开数据库”);
}
}
}
如果([temp isEqualToString:@“false”]){
[SVD解散];
NSString*warning=NSLocalizedString(@“warning”,nil);
NSString*check=NSLocalizedString(@“检查您的用户信息”,无);
NSString*Ok=NSLocalizedString(@“Ok”,nil);
UIAlertView*alertViewUser=[[UIAlertView alloc]initWithTitle:警告
信息:检查
代表:赛尔夫
纽扣:好的
其他按钮类型:无,无];
[alertViewUser show];
alertViewUser.tag=1;
标志=否;
}
否则{
sqlite3*contactDB;
NSArray*dirpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString*docsDir=[dirpath objectAtIndex:0];
NSString*databasePath=[[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:SQL]];
NSFileManager*filemgr=[NSFileManager defaultManager];
如果([filemgr fileExistsAtPath:databasePath]==是)
{
const char*dbpath=[databasePath UTF8String];
if(sqlite3\u打开(dbpath和contactDB)==SQLITE\u正常)
{
对于(int i=0;i<[UrunNo count];i++){
NSString*insertSQL=[NSString stringWithFormat:@“插入到tblKumasBilgi(乌鲁纳迪、乌鲁诺、科勒克西扬、孔波齐西翁、Grm、乌尔米德、En、IslemTipi、迪齐姆、卡尔泰勒科杜、锡利克、欧元、多拉尔、斯特林、TL)值(“%@'、“%@'、”、“%@'、“%@'、”、“%@'、“%'、”、“%'、“%'、”、“%@'、”、“%'、”、”、“%'、”、”、“%'、”、”、”、“%、”、“%、”、”、”、”、“%、”、”、”、”、”、”、”、”、“%、”、”、”、”、“、”、”、”、“,[Koleksiyon objectAtIndex:i]、[Kompozisyon objectAtIndex:i]、[GrM objectAtIndex:i]、[URMID objectAtIndex:i]、[En objectAtIndex:i]、[IslemTipi objectAtIndex:i]、[Dizim objectAtIndex:i]、[KarteleKodu objectAtIndex:i]、[Siklik objectAtIndex:i]、[Euro objectAtIndex:i]、[Dolar objectAtIndex:i]、[Sterlin objectAtIndex:i]、[TL objectAtIndex:i];
//NSLog(@“insert=%@”,insertSQL);
常量字符*sql_stmt=[insertSQL UTF8String];
if(sqlite3_exec(contactDB,sql stmt,NULL,NULL,NULL)==SQLITE_OK)
{
//NSLog(@“插入用户数据成功”);
}
其他的
{
NSLog(@“插入用户数据失败”);
}
}
}
其他的
{
NSLog(@“无法打开数据库”);
}
//sqlite3_关闭(contactDB);
}
[SVD解散];
NSString*warning=NSLocalizedString(@“warning”,nil);
NSString*dataSuccesful=NSLocalizedString(@“数据下载成功”,无);
NSString*Ok=NSLocalizedString(@“Ok”,nil);
UIAlertView*alertViewDownload=[[UIAlertView alloc]initWithTitle:警告
消息:datasuccessful
代表:赛尔夫
坎塞尔布