Skip to content

Instantly share code, notes, and snippets.

@phnessu4
Created May 21, 2013 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phnessu4/5618391 to your computer and use it in GitHub Desktop.
Save phnessu4/5618391 to your computer and use it in GitHub Desktop.
json
NSError *error = nil;
NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];
if (jsonData) {
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
if (error != nil) {
NSAssert(true, @"error is %@", [error localizedDescription]);
}
if ([jsonObjects isKindOfClass:[NSDictionary class]]) {
status = [[jsonObjects valueForKey:@"apistatus"] intValue];
result = [jsonObjects valueForKey:@"result"];
if ([result valueForKey:@"error"] != nil) {
errorCode = [[result valueForKey:@"error_code"] intValue];
errorInfo = [result valueForKey:@"error"];
}
}else{
NSAssert(true, @"not support type to decode json, %@ : %@",jsonObjects, [jsonObjects class]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment