我需要将 "href"
网址显示为 UITableView
中的 cell.textlabel.text
。任何帮助将不胜感激。
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"
},
},
@interface:
@property (strong, nonatomic) NSArray *grandfathers;
@property (strong, nonatomic) NSMutableArray *sons;
@property (strong, nonatomic) NSArray *grandsons;
表格 View :
- (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):
@interface Team : NSObject
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) Links *links;
+ (RKObjectMapping *) mapping;
@end
编辑: 亚历山德罗完美地回答了我的问题,见下文。顺便说一句,他不遗余力地帮助我,我非常感激-
谢谢!
最佳答案
如果正确获取了grandsonLocal
,那么我认为您应该使用
cell.textLabel.text = grandsonLocal.links.api.news.href;
如果这不起作用,请尝试在该行中放置一个断点并检查 grandsonLocal
及其属性的内容。
关于ios - 显示 JSON 响应中的 cell.textLabel.text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16325840/