-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonObject.m
50 lines (33 loc) · 1.15 KB
/
JsonObject.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// JsonObject.m
//
// Licensed by ruralcoder.com under the
// Creative Commons Attribution-ShareAlike 3.0 Unported License
#import "JsonObject.h"
#import "ApplicationLogging.h"
@implementation JsonObject
- (id) init
{
NSAssert(NO, @"Unsupported: Use initWithData instead");
return nil;
}
- (id) initWithData:(NSData*)jsonData
{
NSAssert(jsonData != nil, @"Invalid argument for initWithJsonData jsonData == nil");
NSAssert([jsonData length] > 0, @"Invalid argument for initWithJsonData jsonData has 0 bytes");
// NSString *debugThis = [jsonData toString];
// DLog(@"%@", debugThis);
NSError *jsonParsingError = nil;
NSDictionary *fields = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonParsingError];
if (fields == nil || jsonParsingError != nil)
{
if (jsonParsingError)
ErrorLog(@"Error: %@", [jsonParsingError localizedDescription]);
else
ErrorLog(@"Error: failed to parse json data for unknown reason");
return nil;
}
self = [super initWithDictionary:fields]; // fields retained by base class
return self;
}
@end