-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCJSONDeserializer.m
More file actions
executable file
·63 lines (50 loc) · 1.43 KB
/
Copy pathCJSONDeserializer.m
File metadata and controls
executable file
·63 lines (50 loc) · 1.43 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// CJSONDeserializer.m
// TouchJSON
//
// Created by Jonathan Wight on 12/15/2005.
// Copyright 2005 Toxic Software. All rights reserved.
//
#import "CJSONDeserializer.h"
#import "CJSONScanner.h"
#import "CDataScanner.h"
NSString *const kJSONDeserializerErrorDomain /* = @"CJSONDeserializerErrorDomain" */;
@implementation CJSONDeserializer
+ (id)deserializer
{
return([[[self alloc] init] autorelease]);
}
- (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError;
{
if (inData == NULL || [inData length] == 0)
{
if (outError != NULL && *outError)
*outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
return(NULL);
}
CJSONScanner *theScanner = [CJSONScanner scannerWithData:inData];
NSDictionary *theDictionary = NULL;
if ([theScanner scanJSONDictionary:&theDictionary error:outError] == YES)
return(theDictionary);
else
return(NULL);
}
@end
#pragma mark -
@implementation CJSONDeserializer (CJSONDeserializer_Deprecated)
- (id)deserialize:(NSData *)inData error:(NSError **)outError
{
if (inData == NULL || [inData length] == 0)
{
if (outError != NULL && *outError)
*outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
return(NULL);
}
CJSONScanner *theScanner = [CJSONScanner scannerWithData:inData];
id theObject = NULL;
if ([theScanner scanJSONObject:&theObject error:outError] == YES)
return(theObject);
else
return(NULL);
}
@end