gpt4 book ai didi

ios - 使用Webservice和json parse做排名

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

我是 objective-c 的新手,正在尝试学习一些东西。

我正在使用带有 php 的网络服务创建 Sprite 套件游戏和在线排名。

现在,我只需要获取一个返回前 10 个名称/分数的 json。

我这样做:

NSMutableArray* 诺姆斯; NSMutableArray* 得分;

NSData* jsonDados = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:@"http://www.420blazeitswag.com/wsGame/functions.php?funcao=getRanking"]];


NSError *error;

NSMutableDictionary *jsonRanking = [NSJSONSerialization
JSONObjectWithData:jsonDados
options:NSJSONReadingMutableContainers
error:&error];
NSDictionary* ranking = [jsonRanking objectForKey:@"ranking"];

resultado = [NSMutableArray alloc];
nomes = [ranking objectForKey:@"NOME"];
scores = [ranking objectForKey:@"SCORE"];

NSLog(@"count: %lu\n",[ranking count]);

for(int i=0;i<[ranking count];i++){
[resultado addObject:[NSDictionary dictionaryWithObjectsAndKeys:nomes[i],@"nome",scores[i],@"score", nil]];
NSLog(@"Nome: %@ Score: %@",nomes[i],scores[i]);
}

一旦我执行此代码,我就会收到“CFNetwork SSLHandshake 失败 (-9806)”消息,并且会收到更多消息。

我该怎么办?从现在开始谢谢。

最佳答案

    NSDictionary* ranking = [jsonRanking objectForKey:@"ranking"];

resultado = [NSMutableArray alloc];
nomes = [ranking objectForKey:@"NOME"];
scores = [ranking objectForKey:@"SCORE"];

NSLog(@"count: %lu\n",[ranking count]);

for(int i=0;i<[rankingList count];i++){
[resultado addObject:[NSDictionary dictionaryWithObjectsAndKeys:nomes[i],@"nome",scores[i],@"score", nil]];
NSLog(@"Nome: %@ Score: %@",nomes[i],scores[i]);
}

改成

NSArray* rankingList = [jsonRanking objectForKey:@"ranking"];
nsstring *name;
nsstring *scores;
for(int i=0;i<[rankingList count];i++){
NSDictionary* ranking = [rankingList objectAtList:i];
nomes = [ranking objectForKey:@"NOME"];
scores = [ranking objectForKey:@"SCORE"];
NSLog(@"Nome: %@ Score: %@",nomes,scores);
}

关于ios - 使用Webservice和json parse做排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22465091/

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