Skip to content

Instantly share code, notes, and snippets.

@novalagung
Created July 19, 2013 07:32
Show Gist options
  • Save novalagung/6037370 to your computer and use it in GitHub Desktop.
Save novalagung/6037370 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface DataModel : NSObject
@property (nonatomic, copy) NSString *email;
@property (nonatomic, copy) NSString *password;
@property (nonatomic, copy) NSString *sessionId;
@property (nonatomic, copy) NSString *deviceId;
@property (nonatomic, copy) NSString *encryptionKey;
@end
@implementation DataModel
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
NSMutableArray *dataModels = [NSMutableArray array];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://path/to/webAPI"]];
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if (data) {
NSArray *JSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if (JSON) {
for (NSDictionary *item in JSON) {
DataModel *dataModel = [[DataModel alloc] init];
dataModel.email = [item valueForKeyPath:@"data.usr_email"];
dataModel.password = [item valueForKeyPath:@"data.usr_pass"];
dataModel.sessionId = [item valueForKeyPath:@"header.sess_id"];
dataModel.deviceId = [item valueForKeyPath:@"header.device_id"];
dataModel.encryptionKey = [item valueForKey:@"enc_key"];
[dataModels addObject:dataModel];
}
}
}
NSLog(@"%@", dataModels);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment