ios - 使用Webservice和json parse做排名

标签 ios objective-c json web-services

我是 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/

相关文章:

ios - UILocalNotification scheduleLocalNotification 稍微延迟?

ios - 基于 subview 自动设置容器 View 的高度

objective-c - "{}"表示数组或

ios - 具有多个实例的自定义委托(delegate)方法

mysql - 我可以使用别名或 const 作为 JSON_EXTRACT 函数的 JSON 键吗

ios - 更改两个文本字段的颜色

ios - Swift 运行时错误 (exc_bad_access) AVAudioRecorder, recordSettings

objective-c - 我不能使用 touchesBegan/Moved/Ended 和 UITapGestureRecognizer

java - jcouchdb : svenson unable to parse json string

javascript - 在 DOM 中之前将 jQuery on 'click' 函数分配给 ajax 生成的列表元素