在iPhone上读取由php脚本发送的图像

| EDIT重新制定了问题: 我通过以下方式从使用iphone的服务器加载图像。
NSURL *url = [NSURL urlWithString:@\"http://www.example.de/getImage.php\"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *im = [UIImage imageWithData:data];
imageView.image = im;
php脚本以该行结尾
$image = file_get_contents($direction);
echo $image;
一切都在这里工作。我反映了图像。 现在,我想接收服务器的两个对象,并尝试稍微更改脚本:
echo array(0=>$image , 1=> $intValue);
我尝试读取此数据已有几个小时,但没有得到结果。 为什么这种尝试不起作用?:
NSArray *arr = [[NSArray alloc] initWithContentsOfURL:url];
UIImage *im = [UIImage imageWithData:[arr objectAtIndex:0]];
在调试时,我使用NSLog来获取图像的描述,它为(null)。 没有错别字或编译或语法错误... EDIT001: 好的,我现在可能有点矫kill过正,但是我认为尝试这种方法是不可能的。 我再次使用json_encode和base64_encode,如下所示:
echo json_encode(array(\'a\'=>base64_encode($image), \'b\'=>$anotherObject));
在iPhone方面,我使用了一些框架再次解码JSON和base64,并且可以正常工作... 谢谢,如果您对此有疑问,请写下来     
已邀请:
        在\'json_encode \'的PHP手册页中:   可以是资源以外的任何类型。   此功能仅适用于UTF-8   编码数据 也许将图像作为单独的http get请求发送,这样您就不必担心图像数据的编码/ json解析。     
           $ image = file_get_contents(\'$ direction \');   echo $ image; 如果这是您的文字PHP代码,则会出现错误:\'$ direction \'是文字字符串\'$ direction \'。我无法想象您实际上有一个名为$ direction的文件。不需要将变量放在引号中:
echo file_get_contents( $direction );
    

要回复问题请先登录注册