I was updating my mac app to start using arc and modern obj-c syntax through xcode just to test it our, but one i finish the obj-c syntax i started getting this error when i build the project.
Expected method to read dictionary element not found on object of type ‘NSMutableData *’
-(void) finishedCall:(id)data {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
receivedData = [responseString JSONValue];
NSLog(@"receivedData-->%@",receivedData);
NSString *serailizeString = receivedData[@"profile_image_url"]; // <-- Error comes up here
NSLog (@"Serialize Value : %@",serailizeString);
[qrcodeMainPage genQR:serailizeString];
}
Any suggestions on where to begin?
Thanks in advance!
You’re using the new keyed subscripting syntax to try to access something in (what the compiler thinks is) an NSData object, which, as the error indicates, doesn’t work. Presumably you’re expecting receivedData to be a dictionary? If it is indeed an NSDictionary at runtime, you should declare it as such. I don’t know what the
-JSONValuemethod you’re calling is meant to return, so I can’t say for sure what receivedData is or could be. If it may or may not be a dictionary, you need to write more code to check its type and behave appropriately. In any case, thedictionary[key]notation only works for objects that are instances of a class that supports keyed subscripting. NSDictionary is one of those classes. NSData is not.