gpt4 book ai didi

ios - 如何在 NSMutableArray 中添加包含数组的字符串?

转载 作者:行者123 更新时间:2023-11-28 18:31:01 24 4
gpt4 key购买 nike

我有这个 json

{
"title": "xyz",
"category": "Monetary",
"target": "55",
"achieve": "0",
"todolist": [
{
"todoitem": "one"
},
{
"todoitem": "two"
},
{
"todoitem": "three"
}
]
}

来自 API,我想将 todolist 数组添加到

在.h文件中

@property (strong, nonatomic) NSMutableArray *todolist;
@property (strong, nonatomic) NSMutableArray *todolists;
@property (strong, nonatomic) NSMutableArray *listnumber;

在.m文件中

todolist=[[NSMutableArray alloc] initWithObjects: nil];
todolists=[[NSMutableArray alloc] initWithObjects: nil];
listnumber=[[NSMutableArray alloc] initWithObjects: nil];

在函数中获取json

    todolists = [result valueForKey:@"todolist"];
for (int j =0; j < todolist.count; j++)
{
[todolist addObject:[[todolists objectAtIndex:j] valueForKey:@"todoitem"]];
[listnumber addObject:[NSString stringWithFormat:@"%d", j]];
}

[tvToDoList reloadData];

CellForRowAtIndexPath 我正在为两个字段添加值

            static NSString *CellIdentifier=@"Cell";
TodolistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell==nil)
{
cell = [[TodolistTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier ];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

int row = (int)[indexPath row];

cell.valListitem.text = todolist[row];
cell.lblNo.text = listnumber[row];


return cell;
}

结果包含整个 json

最佳答案

在一行代码中试试这个。

todolist = [[[result valueForKey:@"todolist"] valueForKey:@"todoitem"] mutableCopy];

关于ios - 如何在 NSMutableArray 中添加包含数组的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30340714/

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