首先我有一个NSDictionary
。我执行NSURLRequest
并从请求中加载带有JSON信息的字典。我该如何处理这个Array对象? (Objective-C)
NSDictionary *json =[NSJSONSerialization JSONObjectWithData:response
options:kNilOptions
error:&error];
本字典有2个键值和2个值。 1键=(_ NSCFString)“games”(value:(_NSCFArray *)),另一个是“id”(玩家)。 因为我想要最近的比赛我做[json objectForKey:@"games"]
。现在我得到一个有10个对象的NSArray
。第一个对象列在下面。 如何向我的标签说出哪位冠军(来自冠军ID)玩家玩过或他玩过哪种游戏类型?因为这全部在1个对象中。
如何拆分数组以获取所有信息?
我很感激每一个帮助。 谢谢你的时间。
'NSLogged' [ objectAtIndex:0]
{
championId = 102;
createDate = 1394092919791;
fellowPlayers = (
{
championId = 37;
summonerId = 23497430;
teamId = 200;
},
{
championId = 81;
summonerId = 29757887;
teamId = 200;
},
{
championId = 75;
summonerId = 37419112;
teamId = 100;
},
{
championId = 64;
summonerId = 22985242;
teamId = 100;
},
{
championId = 412;
summonerId = 50506867;
teamId = 100;
},
{
championId = 77;
summonerId = 30770067;
teamId = 200;
},
{
championId = 61;
summonerId = 38231891;
teamId = 200;
},
{
championId = 110;
summonerId = 46318423;
teamId = 100;
},
{
championId = 238;
summonerId = 51117008;
teamId = 100;
}
);
gameId = 1359691076;
gameMode = CLASSIC;
gameType = "MATCHED_GAME";
invalid = 0;
level = 30;
mapId = 1;
spell1 = 4;
spell2 = 14;
stats = {
assists = 3;
championsKilled = 4;
goldEarned = 12280;
goldSpent = 11945;
item0 = 1055;
item1 = 3153;
item2 = 3075;
item3 = 3143;
item4 = 3047;
item5 = 1011;
item6 = 3340;
killingSprees = 2;
largestKillingSpree = 2;
largestMultiKill = 1;
level = 17;
magicDamageDealtPlayer = 68999;
magicDamageDealtToChampions = 5146;
magicDamageTaken = 2044;
minionsKilled = 226;
neutralMinionsKilled = 13;
neutralMinionsKilledEnemyJungle = 12;
neutralMinionsKilledYourJungle = 1;
numDeaths = 1;
physicalDamageDealtPlayer = 71900;
physicalDamageDealtToChampions = 2948;
physicalDamageTaken = 19358;
team = 200;
timePlayed = 1814;
totalDamageDealt = 141513;
totalDamageDealtToChampions = 8708;
totalDamageTaken = 21469;
totalHeal = 3243;
totalTimeCrowdControlDealt = 276;
totalUnitsHealed = 1;
trueDamageDealtPlayer = 614;
trueDamageDealtToChampions = 614;
trueDamageTaken = 66;
turretsKilled = 4;
wardPlaced = 8;
win = 1;
};
subType = "CAP_5x5";
teamId = 200; }
更新1: self.getRecentGames返回一个NSDictionary中(它是不是从self.recentGames吸气)
self.recentGames = [[NSDictionary alloc] initWithDictionary:self.getRecentGames];
NSDictionary *dict = [self.recentGames objectForKey:@"games"];
//now I my dict have 10 object but dict is from type: __NSCFArray
更新2:完了! 非常感谢您的时间。在我检查数组中的对象是否显示它的类之后,它是一个NSDictionary。 非常简单,我只是可以找到它。 你的答案非常有帮助!
你的每个数组对象都是'NSDictionary',对吧?你应该能够使用像这样的东西访问数据:'[((NSDictionary *)[games objectAtIndex:0])valueForKey:@“championId”];' – Romain
你有一个标签数组吗?目前还不清楚你在挣扎什么 - 一个细节清单,简单地从字典中获取一个项目... – Wain
阅读转储。 '{}'包围一个字典,'()'包围一个数组。一次剥离一层。如果需要,写一个循环来搜索你的数组。 (是的,在一个语句中有更奇妙的方法来进行搜索,但是如果你编写循环,你会明白你做得更好。) –