gpt4 book ai didi

ios - 检查 NSMutableDictionary 的值

转载 作者:行者123 更新时间:2023-11-28 20:06:04 25 4
gpt4 key购买 nike

我正在进行包含实时信息的 API 调用。这可以是两种类型的信息。如果有信息,它将返回如下内容:

goaltype = "Regular goal";
id = 2787821;
minute = 45;
player = Nono;
"player_id" = 317569;
playershort = Nono;
team = "Real Betis";
"team_id" = 8603;

如果没有信息返回:

error = "no live games found"

如果它返回错误,我的 tableview 现在会将错误消息计为 1 个对象并返回 1 个单元格。所以如果结果返回错误,那么它不应该运行循环。我怎样才能得到这个或者有其他方法吗?

我的代码:

NSDictionary* headers = @{@"X-Mashape-Authorization": @"MASHAPEKEY"};
NSDictionary* parameters = @{};

UNIHTTPJsonResponse* response = [[UNIRest get:^(UNISimpleRequest* request) {
[request setUrl:@"https://willjw-statsfc-competitions.p.mashape.com/live.json?key=APIKEY&competition=premier-league&timezone=Europe%2FLondon"];

[request setHeaders:headers];
[request setParameters:parameters];
}] asJson];


NSData* rawBody = [response rawBody];
results = [NSJSONSerialization JSONObjectWithData:rawBody options:NSJSONReadingMutableContainers error:nil];




for (int i = 0; i <= results.count-1; i++)
{


NSString *homeTeam = [[results valueForKey:@"homeshort"] objectAtIndex:i ];
NSString *awayTeam = [[results valueForKey:@"awayshort"] objectAtIndex:i ];
NSString *time = [[results valueForKey:@"statusshort"] objectAtIndex:i ];
NSString *homeScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:0]];
NSString *awayScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:1]];


[arrayBarclay addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:homeTeam,@"hometeam", awayTeam,@"awayteam", time, @"time", homeScore, @"homescore", awayScore, @"awayscore", nil]];

}

最佳答案

如果看不到 error 键,这意味着您正在获取预期的数据,因此对结果集进行迭代预计是安全的。

if(![result valueForKey:@"error"])
{
for (int i = 0; i <= results.count-1; i++)
{


NSString *homeTeam = [[results valueForKey:@"homeshort"] objectAtIndex:i ];
NSString *awayTeam = [[results valueForKey:@"awayshort"] objectAtIndex:i ];
NSString *time = [[results valueForKey:@"statusshort"] objectAtIndex:i ];
NSString *homeScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:0]];
NSString *awayScore = [NSString stringWithFormat:@"%@", [[[results valueForKey:@"runningscore"] objectAtIndex:i ] objectAtIndex:1]];


[arrayBarclay addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:homeTeam,@"hometeam", awayTeam,@"awayteam", time, @"time", homeScore, @"homescore", awayScore, @"awayscore", nil]];

}
}

关于ios - 检查 NSMutableDictionary 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078162/

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