gpt4 book ai didi

ios - Objective C TableView 清晰 Json 解析

转载 作者:行者123 更新时间:2023-11-29 01:27:22 28 4
gpt4 key购买 nike

我有手动数据的工作项目,但我想在我的项目中添加 json 解析。我认为我需要帮助。 (必须是实时解析,如果可能的话,新的item添加时会自动释放)

我的 TableView 代码

- (void)scrollToLastTableViewCell {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.uniqueCodes.count - 1
inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellid=@"CustomCell";
CustomTableViewCell *cell=(CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid];;


if(cell==nil)
{
cell=[[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];

}
cell.nameLabel.text=[NSString stringWithFormat:@"This is cell no %d of this table",indexPath.row+1];
cell.cellButton1.tag=101+indexPath.row;
cell.cellButton2.tag=201+indexPath.row;
cell.cellButton3.tag=202+indexPath.row;
cell.cellButton4.tag=203+indexPath.row;
cell.cellButton5.tag=204+indexPath.row;
cell.SwipableUIView.tag=301+indexPath.row;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];


return cell;
}

CustomTableViewCell.h

@interface CustomTableViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIView *SwipableUIView;
@property (weak, nonatomic) IBOutlet UIButton *cellButton1;
@property (weak, nonatomic) IBOutlet UIButton *cellButton2;
@property (weak, nonatomic) IBOutlet UIButton *cellButton3;
@property (weak, nonatomic) IBOutlet UIButton *cellButton4;
@property (weak, nonatomic) IBOutlet UIButton *cellButton5;
@property (weak, nonatomic) IBOutlet UIButton *cellButton6;
@property (weak, nonatomic) IBOutlet UIButton *cellButton7;

@end

我的杰森

{

"Items": [
{
"name": "My new name 1"
},
{
"name": "My new name 2"
},
{
"name": "My new name 3"
}
]
}

谢谢你所做的一切。

最佳答案

您是否只是想从 JSON 中解析出唯一的代码,如下所示:

NSString *jsonString = /* Your JSON String Here */;
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *serializationError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&serializationError];
NSMutableArray *uniqueCodes = json[@"Items"];

关于ios - Objective C TableView 清晰 Json 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33854255/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com