Ios 我正在尝试以下代码,但它引发异常

Ios 我正在尝试以下代码,但它引发异常,ios,Ios,例外情况详情如下: 2015-02-19 13:09:02.825 try11feb2[377:11303]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'*-[\uu NSArrayM insertObject:atIndex:]:对象不能为零' ***第一次抛出调用堆栈: (0x1c92012 0x10cfe7e 0x1c45b6a 0x1c45a20 0x26ab 0xbd5589 0xbd3652 0xbd489a 0xbd360d 0x

例外情况详情如下: 2015-02-19 13:09:02.825 try11feb2[377:11303]*由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'*-[\uu NSArrayM insertObject:atIndex:]:对象不能为零' ***第一次抛出调用堆栈: (0x1c92012 0x10cfe7e 0x1c45b6a 0x1c45a20 0x26ab 0xbd5589 0xbd3652 0xbd489a 0xbd360d 0xbd3785 0xb20a68 0x46156dc 0x4613bb3 0x4651cda 0x1c348fd 0x465235c 0x46522d5 0x453c250 0x1c15f3f 0x1c1596f 0x1c38734 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x1c3d 0x1B065 0x1) libc++abi.dylib:terminate调用引发异常 (lldb)

导入“xyzViewController.h”
您的解析代码完全错误。我不知道您需要在表视图中加载什么值…例如,我解析了一个标签键值。这可能会对您有所帮助,只需更改此代码

    @interface xyzViewController ()

    @end

    @implementation xyzViewController
    @synthesize mytv;

    - (void)viewDidLoad
    {
        tabledata=[[NSMutableArray alloc]init];
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    - (IBAction)btnpressed:(id)sender {

        NSString *str=@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/json";
        NSURL *url=[[NSURL alloc]initWithString:str];
        NSURLRequest *req=[[NSURLRequest alloc]initWithURL:url];
        conn=[[NSURLConnection alloc]initWithRequest:req delegate:self];
        if (conn) {
            webdata=[[NSMutableData alloc]init];
        }

    }
    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        [webdata setLength:0];
    }
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [webdata appendData:data];
    }
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        NSLog(@"failed");
    }
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {

        NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
        NSDictionary *feed=[ald objectForKey:@"feed"];
        NSArray *arrayofentry=[feed objectForKey:@"entry"];
        for (NSDictionary *dic in arrayofentry)
        {  NSDictionary *zero=[dic objectForKey:0];
            NSDictionary *title=[zero objectForKey:@"title"];
            NSString *label=[title objectForKey:@"label"];

            [tabledata addObject:label];
             // NSLog(@"%@",label);}
          //  tabledata =[[NSArray alloc]initWithObjects:label, nil];
            [[self mytv]reloadData];
        }
[[self mytv]reloadData];
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [tabledata count];
    }
    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellIdentifier=@"cell";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

        }
cell.textLabel.text=[tabledata objectAtIndex:indexPath.row];
        return cell;
    }
    @end
编辑:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
    NSDictionary *feed=[ald objectForKey:@"feed"];
    NSArray *arrayofentry=[feed objectForKey:@"entry"];
    NSLog(@"%@",arrayofentry);
    for (NSDictionary *dic in arrayofentry)
    {
        NSDictionary *zero=[dic objectForKey:@"category"];
        NSString *label=[[zero objectForKey:@"attributes"]valueForKey:@"label"];

        [tabledata addObject:label];

    }
    [[self mtv]reloadData];
}

如果要分析另一个值,请告诉我。

您试图传递的密钥可能重复NSDictionary*zero=[dic objectForKey:0];你有零字典中的值吗?应该在for循环之后重新加载数据,并添加以下行单元格。textlab.text=[tabledata objectAtIndex:indexPath.row];在返回一个不处于if状态的单元格之前。先生,我已经编辑了我的代码。但是它不再工作了。您需要在tableview中加载什么键值?@karthikeyan我正在解析来自()的前十首歌曲名称。先生,我正在解析来自(ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/…)的前十首歌曲的键值。好的,告诉我前十首歌曲的键值或它来自何处,您的josnSir的口述,()这是json数据的链接,我想在其中选择条目数组中的标题键。我想现在你的问题已经解决了。我希望这有助于看到我编辑过的答案
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
    NSDictionary *feed=[ald objectForKey:@"feed"];
    NSArray *arrayofentry=[feed objectForKey:@"entry"];
    NSLog(@"%@",arrayofentry);
    for (NSDictionary *dic in arrayofentry)
    {
        NSDictionary *zero=[dic objectForKey:@"category"];
        NSString *label=[[zero objectForKey:@"attributes"]valueForKey:@"label"];

        [tabledata addObject:label];

    }
    [[self mtv]reloadData];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSDictionary *ald=[NSJSONSerialization JSONObjectWithData:webdata options:0 error:Nil];
    NSDictionary *feed=[ald objectForKey:@"feed"];
    NSLog(@"%@",[feed allKeys]);
    NSArray *arrayofentry=[feed objectForKey:@"entry"];
    NSLog(@"%@",arrayofentry);
    for (NSDictionary *dic in arrayofentry)
    {
        //THIS LINE TELL YOU THAT ALL THE AVAILABLE KEYS IN DICTIONARY
        NSLog(@"%@",[dic allKeys]);

//        NSDictionary *zero=[dic objectForKey:@"category"];
//        NSString *label=[[zero objectForKey:@"attributes"]valueForKey:@"label"];


        // NSDictionary *zero=[dic objectForKey:@"title"];
        NSString *label=[[dic objectForKey:@"title"]valueForKey:@"label"];
        [tabledata addObject:label];

    }
    [[self mtv]reloadData];
}