gpt4 book ai didi

objective-c - 从数组打印

转载 作者:行者123 更新时间:2023-12-03 17:34:42 24 4
gpt4 key购买 nike

我试图从数组中获取一些数据并将其打印在 Xcode 中的 UILabel 上,但我收到警告:

Incompatible pointer types assigning to 'NSString *' from 'NSArray *'

这是我的代码:

NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&myError];
NSArray *results = [res objectForKey:@"current_observation"];
NSArray *cur = [results valueForKey:@"weather"];
NSArray *tmp = [results valueForKey:@"temp_c"];
NSLog(@"Current conditions: %@, %@º", cur, tmp);

temp.text = (@"%@", tmp);

最佳答案

而不是这个:

temp.text = (@"%@", tmp);

使用这个:

temp.text = [tmp componentsJoinedByString:@""];

关于objective-c - 从数组打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16520141/

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