Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.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图像URL解析为自定义表视图错误_Ios_Json_Xcode_Parsing - Fatal编程技术网

Ios 将JSON图像URL解析为自定义表视图错误

Ios 将JSON图像URL解析为自定义表视图错误,ios,json,xcode,parsing,Ios,Json,Xcode,Parsing,我试图解析一个JSON文件,其中包含一些图片、标题和文本的url。我试着用同样的方法解析另一个JSON文件,但只使用文本,而且它可以工作。但是这个不行。这是我的密码: .h: 我有一个名为PictureJSON的自定义表视图文件,其中包含一个nib文件,如下所示: 但当我启动我的应用程序时,会出现以下错误: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PicturesViewC

我试图解析一个JSON文件,其中包含一些图片、标题和文本的url。我试着用同样的方法解析另一个JSON文件,但只使用文本,而且它可以工作。但是这个不行。这是我的密码:

.h:

我有一个名为PictureJSON的自定义表视图文件,其中包含一个nib文件,如下所示:

但当我启动我的应用程序时,会出现以下错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PicturesViewController 0x17d86dc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key instaImage.'
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合密钥instaImage的键值编码。”
有人能帮我修一下吗?
谢谢

可能您得到的JSON结构不好,请检查中的查询结果,也许这可以帮助您检测错误。

就在这一行前面
cell.instaImage=[tweet objectForKey:@“link”]
(这是导致异常的原因),您是否检查过
cell
是否是
PictureJSON
的实例,而不是
UITableViewCell
?嗯,我不确定。你怎么检查@neilcoA一个简单的方法是在我提到的行之前添加它:
NSLog(@“%@,[cell class])这将把单元格类型的名称写入Xcode中的控制台。
#import "PicturesViewController.h"
#import "AppDelegate.h"
#import "RNBlurModalView.h"
#import "PictureJSON.h"

@interface PicturesViewController ()
{
    NSInteger refreshIndex;
    NSArray *images;
}

@end

@implementation PicturesViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(showMenu)];

    UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
    [self.view addGestureRecognizer:gestureRecognizer];

     [self issueLoadRequest];
}

- (void)swipeHandler:(UIPanGestureRecognizer *)sender
{
    [[self sideMenu] showFromPanGesture:sender];
}

#pragma mark -
#pragma mark Button actions

- (void)showMenu
{
    [[self sideMenu] show];
}

#pragma mark - Table view data source


- (void)issueLoadRequest
{
    // Dispatch this block asynchronosly. The block gets JSON data from the specified URL and performs the proper selector when done.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://my-site/pictureparse.php?name=MyName"]];
        [self performSelectorOnMainThread:@selector(receiveData:) withObject:data waitUntilDone:YES];
    });
}

- (void)receiveData:(NSData *)data {
    // When we have the data, we serialize it into native cocoa objects. (The outermost element from twitter is
    self.tweets = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    [self.myTableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tweets.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"PictureJSON";

    PictureJSON *cell = (PictureJSON *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PictureJSON" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    NSDictionary *tweet = [self.tweets objectAtIndex:indexPath.row];
    cell.instaImage = [tweet objectForKey:@"link"];
    cell.titleLabel.text = [tweet objectForKey:@"title"];
    cell.timeLabel.text = [tweet objectForKey:@"published"];

    return cell;
}

@end
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PicturesViewController 0x17d86dc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key instaImage.'