NSMutableArray with NSDictionary to Labels without the surrounding brackets
I'm making a scoreboard for my game. And when I do a NSLog of the data it comes out as this:
{
name = TTY;
score = "3.366347";
}
So my question is how do I remove this brackets and also just grab the name (TTY) and score (3.36 witho开发者_如何学编程ut the quotations) and place them in variable for me to put into labels.
Currently I can place them in labels but they have the lingering curly braces "{" and "}".
Any hints would be helpful as I'm happy to search further I just don't know the vocab to search for it.
thanks
For NSDictionary if you want to get the values you use objectForKey:
method;
[scoreDictionary objectForKey:@"name"];
In your case the method will return TTY
You can store this in a variable like normal:
NSString *entryName = [scoreDictionary objectForKey:@"name"];
For NSArray (and NSMutableArray) you use objectAtIndex:
method;
[scoresArray objectAtIndex:0];
I'm guessing that you have many NSDictionary in the NSArray, in which case you can combine the two methods above and get;
[[scoresArray objectAtIndex:0] objectForKey:@"name"];
which will give you the value of name
in the first dictionary of the array.
Also if you want to access multiple key values you can use;
NSDictionary *entry = [scoresArray objectAtIndex:0];
NSString *entryName = [entry objectForKey:@"name"];
NSString *entryScore = [entry objectForKey:@"score"];
精彩评论