Iphone Json解析数据

Iphone Json解析数据,iphone,json,uitableview,Iphone,Json,Uitableview,我已经尝试过几次了,但我仍然不知道如何进入JSON提要并检索需要获取的内容 feed看起来是这样的,在我的代码中,我试图取出所有的标题。我不知道如何进入Json提要 - (void)viewDidLoad { [super viewDidLoad]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSURL *url = [NS

我已经尝试过几次了,但我仍然不知道如何进入JSON提要并检索需要获取的内容

feed看起来是这样的,在我的代码中,我试图取出所有的标题。我不知道如何进入Json提要

    - (void)viewDidLoad
    {
        [super viewDidLoad];


        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

        NSURL *url = [NSURL URLWithString:@"http://api.storageroomapp.com/accounts/511a4f810f66026b640007b8/collections/511a51580f66023bff000ce9/entries.json?auth_token=Zty6nKsFyqpy7Yp5DP1L&preview_api=1"];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [[NSURLConnection alloc] initWithRequest:request delegate:self];



        // Do any additional setup after loading the view from its nib.
    }

    -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
        data = [[NSMutableData alloc] init];
    }
    -(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{
        [data appendData:theData];
    }
    -(void)connectionDidFinishLoading:(NSURLConnection *) connection{
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

        news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
        [mainTableView reloadData];
    }

    -(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
        UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The data could not be downloaded - please make sure you're connected to either 3G or Wi-FI" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [errorView show];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }


    -(int)numberOfSectionsInTableView:(UITableView *)tableView{
        return  1;
    }
    -(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return [news count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];


            cell.textLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"title"];

        }

        return cell;
    }

在我的H里我有NSArray*新闻;和NSMutableData*数据


任何帮助都会很好,你能解释清楚你自己吗,因为我对这门语言完全是新手

查看代码中的逻辑和发布的示例JSON,您的数组似乎没有填充您想要的内容

最初,JSON是字典的形式(因此在您提供的图像中使用了大括号)。因此,您应该调整JSON的初始解析,如下所示:

NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
从这里,您可以从字典接收密钥。您要查找的是“array”,它实际上也是一个字典,尽管它的名称不同

NSDictionary *arrayDictionary = dictionary[@"array"];
继续前进,您最终可以访问正在查找的“资源”数组,并将其存储在您在.h文件中创建的实例变量中

news = arrayDictionary[@"resources"];
现在,在
cellforrowatinexpath
方法中,您可以根据提供给您的索引路径行访问此数组的各种元素

NSDictionary *newsItem = news[[indexPath row]];
最后,您可以访问各种属性,例如来自该新闻项的标题,并设置文本标签的文本

NSString *title = newsItem[@"title"];
[[cell textLabel] setText:title];

嗨,如果我上传了zip,你能不能快速看一下,发现很难理解。好吧,看看你在哪里解析字典,并根据我在帖子中所说的调整它。最后,我还向您指出访问标题所需的方法和逻辑。试一试,如果你有任何问题,请回答。对不起,我不明白最后一点?你到底有什么问题?我上传了它,使它更容易,因为我发现它很难解释。xib/m/h是客户指南。非常感谢