Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Iphone 未显示来自远程数据库的图像_Iphone_Json_Web Services_Uiimage - Fatal编程技术网

Iphone 未显示来自远程数据库的图像

Iphone 未显示来自远程数据库的图像,iphone,json,web-services,uiimage,Iphone,Json,Web Services,Uiimage,我将图像存储在远程服务器中。然后我使用JSON框架从数据库中获取数据。我使用NSLog显示id、名称、图像名称。但是图像没有显示出来。我使用BLOB在本地存储图像。但当我将数组用于NSLog时,它会显示一些encript值 代码: 可能重复你的另一个问题。但正如我在回答另一个问题时所讨论的,您的sql返回一列id,然后继续尝试从不存在的第四列检索图像。 sofArray = [[NSMutableArray alloc] init]; NSFileManager *fileMgr

我将图像存储在远程服务器中。然后我使用JSON框架从数据库中获取数据。我使用NSLog显示id、名称、图像名称。但是图像没有显示出来。我使用
BLOB
在本地存储图像。但当我将数组用于NSLog时,它会显示一些encript值

代码:


可能重复你的另一个问题。但正如我在回答另一个问题时所讨论的,您的
sql
返回一列
id
,然后继续尝试从不存在的第四列检索图像。
sofArray = [[NSMutableArray alloc] init];  


    NSFileManager *fileMgr = [NSFileManager defaultManager];
    NSError *err;

    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Empty" ofType:@"sqlite"];
    //NSLog(@"bundlePath %@", bundlePath);


    //call update function to check any data updated,
    //if there is a version difference
    //update the data base with all the required fileds.



    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    //NSLog(@"docs dir is %@", documentsDirectory);

    NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"App10.sqlite"];

    [fileMgr copyItemAtPath:bundlePath toPath:appFile error:&err];

 NSURL *URL = [NSURL URLWithString:@"http://server.net/projects/mobile/jsonstring.php"];

    NSLog(@"URL is %@", URL);


     NSError *error;
     NSString *stringFromFileAtURL = [[NSString alloc]
     initWithContentsOfURL:URL
     encoding:NSUTF8StringEncoding
     error:&error];

     //NSLog(@"response is %@", stringFromFileAtURL);

     NSString *path = [documentsDirectory stringByAppendingPathComponent:@"App10.sqlite"];


     NSArray *userData = [stringFromFileAtURL JSONValue];

     // NSArray *skarray = [[NSArray alloc]init];



    NSLog(@"userdata is %@", userData);

   // int  i = 0;
    BOOL notExist = TRUE;


     for (NSArray *skarray in userData) {

     for (NSDictionary *tuser in skarray) {

   //  if (sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK) {


         if (sqlite3_open([path UTF8String], &db) == SQLITE_OK) {

       //  const char *sql = "SELECT * FROM categories";

   //  const char *sql = [[NSString stringWithFormat:@"SELECT id FROM categories where cat_id = '%@'",[tuser objectForKey:@"cat_id"]] cStringUsingEncoding:NSUTF8StringEncoding];


      const char *sql = [[NSString stringWithFormat:@"SELECT id FROM categories where id = '%@'",[tuser objectForKey:@"id"]] cStringUsingEncoding:NSUTF8StringEncoding];     

     //NSLog(@"check stmt is %s", sql);

     sqlite3_stmt *sqlStatement,*addStmt;

     if (sqlite3_prepare_v2(db, sql, -1, &sqlStatement, NULL) == SQLITE_OK) {

       notExist = TRUE;

     while (sqlite3_step(sqlStatement) == SQLITE_ROW) {

        notExist = FALSE;


     Mysof *Mylist = [[Mysof alloc]init];
     Mylist.sofaId = sqlite3_column_int(sqlStatement, 0);
     Mylist.sofa = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
     Mylist.rating = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement, 2)];



     const char *raw = sqlite3_column_blob(sqlStatement, 3);
     int rawLen = sqlite3_column_bytes(sqlStatement, 3);
     NSData *data = [NSData dataWithBytes:raw length:rawLen];
     Mylist.photo = [[UIImage alloc] initWithData:data];
     [sofArray addObject:Mylist];

  }

         if(notExist){
             //NSLog(@"cat id does not exist");

             const char *sqlInsert = [[NSString stringWithFormat:@"insert into categories (id, cat_name,order_by) values ('%@', '%@', '%@')", [tuser objectForKey:@"id"], [tuser objectForKey:@"cat_name"],[tuser objectForKey:@"order_by"]] cStringUsingEncoding:NSUTF8StringEncoding];
             //NSLog(@"stmt is %s", sqlInsert);

             if(sqlite3_prepare_v2(db, sqlInsert, -1, &addStmt, NULL) != SQLITE_OK)
                 NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(db));

             if(SQLITE_DONE != sqlite3_step(addStmt))
                 NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(db));

         }


     }

     }

     }

     }


return sofArray;