First, let me show you the piece of code:
NSURL *url = [NSURL URLWithString:@"http://www....../struct1.js"];
//create a NSData file from url.
NSData *myData = [NSData dataWithContentsOfURL:url];
NSError *theError = nil;
//some framework
NSDictionary *dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:myData error:&theError];
NSString * products;
for(id key in dict){
NSLog(@"key: %@, value: %@",key,[dict objectForKey:key]);
if([key isEqualToString:@"product_reviews"]){
products = (NSString *)[dict valueForKey:key];
break;
}
}
//gives an error at the execution, why?
NSLog(@"products : %@",[NSString stringWithString:products]);
I get an error at the execution, like products
was not NSString, is it not? why can't i cast it?
Here is the error :
0x00e0eb2c __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3246 + 68
19 UIKit 0x00de5b8a -[UIApplication workspaceDidEndTransaction:] + 163
2123
31 UIKit 0x00de52da -[UIApplication _run] + 540
........ .....
32 UIKit 0x00deaeb9 UIApplicationMain + 160
33 App1 0x000416ca main + 138
34 libdyld.dylib 0x03156a25 start + 1
) libc++abi.dylib: terminating with uncaught exception of type NSException