我需要将"href"
网址显示cell.textlabel.text
为UITableView
. 任何帮助将不胜感激。
JSON:
"grandfathers": [{
"id": "60",
"sons": [{
"id": "30",
"grandsons": [{
"id": "10",
"links": {
"api": {
"news": {
"href": "http://api.website.com/v1/family/grandfathers/sons/grandsons/10/news"
},
},
@界面:
@property (strong, nonatomic) NSArray *grandfathers;
@property (strong, nonatomic) NSMutableArray *sons;
@property (strong, nonatomic) NSArray *grandsons;
表视图:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"standardCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Grandfather *grandfatherLocal = [grandfathers objectAtIndex:0];
Son *sonLocal = [grandfatherLocal.sons objectAtIndex:0];
// Not sure what to do here to get to the "href" eventually
// This was my best guess...
Grandson *grandsonLocal = [sonLocal.grandsons objectAtIndex:indexPath.row];
cell.textLabel.text = [grandsonLocal.links.api.news.href valueForKey:@"href"];
};
我不确定当时如何获取嵌套数据。(仅供参考,我设置了模型并使用了 RestKit,这就是我在这里所做的事情的背景。)
编辑: 我没有在表中显示任何内容,输出中的错误只是:“找不到 keyPath 的对象映射:''”
编辑: 每个请求的孙子接口:
@interface Team : NSObject
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) Links *links;
+ (RKObjectMapping *) mapping;
@end
编辑: 亚历山德罗完美地回答了我的问题,见下文。顺便说一句,他不遗余力地帮助我,我非常感激-
谢谢!