gpt4 book ai didi

ios - 如何从 NSDictionary 数组中获取值数组

转载 作者:行者123 更新时间:2023-11-28 19:06:24 26 4
gpt4 key购买 nike

当我尝试在日志中打印 json 值数组时,我得到的是地址而不是值。这是我的编码方式。

NSData *jsonData = [json dataUsingEncoding:NSASCIIStringEncoding];
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:jsonArray.count];
NSMutableArray *anotherTempArray = [NSMutableArray arrayWithCapacity:jsonArray.count];
NSDictionary *dict;
for(dict in jsonArray)
{
NSString *projectName = dict[@"Name"];

NSString *urlText = dict[@"Url"];
NSLog(@"Url text in array = %@", urlText);

NSString *attch = dict[@"attachmentes"];
NSLog(@"Attached url in array = %@", attch);

NSString *projID = dict[@"ProjectID"];
NSLog(@"Project ID in array = %@", projID);

SaveAttachment *saveAt = [[SaveAttachment alloc] initWithName:projectName withList:@"View" withAttachment:@"View"];
[tempArray addObject:saveAt];

SaveProjectId *saveProj = [[SaveProjectId alloc] initWithProjectId:projID];
saveProj.projectId = projID;
[anotherTempArray addObject:saveProj];
}
array = tempArray;
[self.tableViewProject reloadData];
NSLog(@"Array of project IDs === %@", anotherTempArray); //Get values (array of project ids here.

}

enter image description here

最佳答案

替换

SaveProjectId *saveProj = [[SaveProjectId alloc] initWithProjectId:projID];
saveProj.projectId = projID;
[anotherTempArray addObject:saveProj];

[anotherTempArray addObject:projID];

关于ios - 如何从 NSDictionary 数组中获取值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20068074/

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