Reputation: 799
My NSDictionary output with NSLog shows:
{
"filename" : "mytest100.txt",
"filedesc" : "File Description here",
"data" : [
]
}
But when I do: NSString *filename = [dict objectForKey:@"filename"];
it crashes on this line.
What am I doing wrong? This seems trivial.
Upvotes: 1
Views: 501
Reputation: 62676
Try this:
NSDictionary *d = [NSDictionary dictionaryWithObject:@"foo" forKey:@"bar"];
NSLog(@"%@", d);
output is:
{
bar = foo;
}
Notice that there are no quotes logged in the key or value? Unless your key and value is of the form @"\"foo\"", my guess is that you don't really have a dictionary there.
I'd put my money on a string representing JSON. The crash is because objectForKey: is an unrecognized selector on a string.
Upvotes: 3
Reputation: 13685
From the error message you're getting, the dict
variable does not hold an NSDictionary
, but rather and NSString
.
Track back up your code looking for where you assign the dict
variable and you'll surely see it's being set to something that's not a dictionary.
Upvotes: 2