Hi I am using NSJSONSerialization to decode json data thats coming from a webserver for my ios application. Earlier it was working fine and decoding perfectly. Suddenly now, the decoding only returns me (null). I even replaced the code with a hard coded json string as you can see below, but the system is simply returning me (null) responses for everything. I have tried placing this code snippet in different parts of the application with no change. Any ideas on why it suddenly stopped working? Below is the hardcoded version
NSError *error;
NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [@"{\"testdata\":\"1.1\"}" dataUsingEncoding:NSUTF8StringEncoding] options: NSJSONReadingMutableContainers error: &error];
NSLog(@"Hardcoded JSON %@", JSON);
NSLog(@"Error in JSON is %@", [error localizedDescription]);
NSString *data = [NSString stringWithFormat:@"%@",[jsonDict valueForKey:@"testdata"]];
NSLog(@"Data received %@", data);
The Log for the same is:
2013-11-08 04:13:57- Hardcoded JSON (null) 2013-11-08 04:13:57- Error in JSON is (null) 2013-11-08 04:13:57- Data received (null)
Try this
Error *error;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:nil error:&error];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.