Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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
Ios 应用程序中对UIImageView的图像URL JSON解析错误_Ios_Json_Parsing - Fatal编程技术网

Ios 应用程序中对UIImageView的图像URL JSON解析错误

Ios 应用程序中对UIImageView的图像URL JSON解析错误,ios,json,parsing,Ios,Json,Parsing,我试图在iPhone应用程序中通过JSON解析图像url。 我的json模型是这样构建的: { "picture":"link_to_image.jpg", "about":"about text here", "name":"Name" } 我使用以下代码解析我的应用程序中的itemw: - (void)fetchedData:(NSData *)responseData { NSError *error; NSDictionary *json = [NSJ

我试图在iPhone应用程序中通过JSON解析图像url。 我的json模型是这样构建的:

{
   "picture":"link_to_image.jpg",
   "about":"about text here",
   "name":"Name"
}
我使用以下代码解析我的应用程序中的itemw:

- (void)fetchedData:(NSData *)responseData
{
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData
                                                         options:kNilOptions error:&error];

    self.titleLabel.text = [json objectForKey:@"name"];
    self.aboutText.text = [json objectForKey:@"about"];
    self.profileImage.image = [json objectForKey:@"picture"];
}
在ViewDidLoad中,我写了以下内容:

dispatch_queue_t queue = dispatch_get_global_queue
    (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
       dispatch_async(queue,  ^{
        NSData *data = [NSData dataWithContentsOfURL:
                        [NSURL URLWithString:@"link_to_my_json_file.php"]];
        [self performSelectorOnMainThread:@selector(fetchedData:)
                               withObject:data waitUntilDone:YES];
    });
我已将插座连接到.xib文件中的项目,标题和关于文本已成功解析为标签和文本视图。但是图像不会被解析。当我尝试对图像执行此操作时,应用程序不断崩溃

有人能解释一下我做错了什么吗


谢谢

正如@hotlicks在评论中提到的,您正在将NSString指针放入UIImage属性中。下面的方法应该有效

- (void)fetchedData:(NSData *)responseData
{
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData
                                                         options:kNilOptions error:&error];
    self.titleLabel.text = [json objectForKey:@"name"];
    self.aboutText.text = [json objectForKey:@"about"];
    NSURL *URL = [NSURL URLWithString: [json objectForKey:@"picture"]];
    dispatch_queue_t queue = dispatch_get_global_queue
    (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
       dispatch_async(queue,  ^{
        NSData *data = [NSData dataWithContentsOfURL: URL];
        self.profileImage.image = [UIImage imageWithData: data];
    });
}

也许你可以先解释一下你在做什么。(你意识到你把一个NSString指针放进self.profileImage.image,对吧?它不是一个映像,只是它的名字。)(而且你还意识到,由于你是异步调度代码,所以它的结果不会立即可用,对吗?)当应用程序崩溃时,你会收到什么消息?对不起。我现在才刚开始学习Objective-C。。。NSLog说:“由于未捕获的异常‘NSInvalidArgumentException’而终止应用程序,原因:”-[\uu NSCFString\u isResizable]:…“@hotlicksb但需要注意的是,这些值都不会在viewdiload中的序列退出时设置,但会在稍后的某个时间设置。我在以下行中得到“Parse Issue Expected identifier”:NSURL*URL=[[NSURL URLWithString:[json objectForKey:@“picture”]];@DavidGabor-数一数你的括号。我已删除了一个括号。