This is the json coming from the server:
{
"name":"channelname",
"args":
[
{
"username":"myusername",
"message":"mymessage"
}
]
}
Using ios5 built-in json methods I try to parse out the args's username/message.
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: [packet.data dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: nil];
NSDictionary *argsValues = [[NSDictionary alloc] initWithDictionary:[JSON objectForKey:@"args"]];
Second line throws an error:
dictionary argument is not an NSDictionary
When I NSlog [JSON objectForKey@"args"] I get:
(
{
message = mymessage;
username = myusername;
}
)
I think the parenthesis are breaking it, don't know where they came from, help appreciated.
EDIT:
Thanks to chosen answer, here's the code I used to get the args keys.
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData: [packet.data dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableLeaves error: nil];
NSArray *argsArray = [[NSArray alloc] initWithArray:[JSON objectForKey:@"args"]];
NSDictionary *argsDict = [[NSDictionary alloc] initWithDictionary:[argsArray objectAtIndex:0]];
NSLog(@"keys = %@", [argsDict allKeys]);