forked from chrissearle/Collection-JSON-ObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CJCollection.m
34 lines (24 loc) · 882 Bytes
/
CJCollection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#import "CJCollection.h"
#import "CJLink.h"
#import "CJItem.h"
@implementation CJCollection
@synthesize links;
@synthesize items;
@synthesize version;
@synthesize href;
+ (CJCollection *) collectionForNSData:(NSData *)data {
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
NSLog(@"JSON: %@", json);
CJCollection *collection = [[CJCollection alloc] init];
NSDictionary *dict = [json objectForKey:@"collection"];
collection.version = [dict objectForKey:@"version"];
collection.href = [NSURL URLWithString:[dict objectForKey:@"href"]];
collection.links = [CJLink linksForDictionary:dict];
collection.items = [CJItem itemsForDictionary:dict];
return collection;
}
@end