Vote count:
0
I am creating an app the scans barcodes and retrieves information from a web service.
I have a web service set up that is returning values in JSON format. When logging all values within the JSON everything works fine. The problem is when trying to log single values. The app crashes and I see this:
- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x170224f40' *
Doing plenty of research I have come across a few question here that resemble the same problem I am encountering. Some are of great help sending me in the proper direction. I still cannot find a solution to why this is happening though.
Here is the code where the app is crashing:
//NSDisctionary
res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
for(id key in res) {
id value = [res objectForKey:key];
NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;
NSLog(@"key: %@", keyAsString);
NSLog(@"value: %@", valueAsString);
}
//NSMutableArray
results = [res objectForKey:@"error"];
//result is a dictionary
for (result in results) {
message = [result objectForKey:@"message"];
NSLog(@"Code Above: %@", message);
}
This is what my JSON looks like:
{ "error": { "code": 1, "message": "No UPC Code for this scan" }, "data": null }
Is anyone able to see where I am going wrong here? A hint in the right direction would be truly appreciated.
Thanks so much.
Aucun commentaire:
Enregistrer un commentaire