|
34 | 34 | **IMPORTANT:** The `^` block MUST return an object with a class that can be serialized by JSONKit, otherwise the serialization will fail. |
35 | 35 |
|
36 | 36 | <pre> |
37 | | - ​- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError \*\*)error; |
38 | | - ​- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(^)(id object))block error:(NSError \*\*)error; |
| 37 | + ​- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(\^)(id object))block error:(NSError \*\*)error; |
| 38 | + ​- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(\^)(id object))block error:(NSError \*\*)error; |
39 | 39 | </pre> |
40 | 40 |
|
41 | 41 | Example using the delegate way: |
|
74 | 74 |
|
75 | 75 | NSString \*jsonString = NULL; |
76 | 76 | jsonString = [array JSONStringWithOptions:JKSerializeOptionNone |
77 | | - serializeUnsupportedClassesUsingDelegate:myFormatter |
78 | | - selector:@selector(formatObject:) |
79 | | - error:NULL]; |
| 77 | + serializeUnsupportedClassesUsingDelegate:myFormatter |
| 78 | + selector:@selector(formatObject:) |
| 79 | + error:NULL]; |
80 | 80 | NSLog(@"jsonString: '%@'", jsonString); |
81 | 81 | // 2011-03-25 11:42:16.175 formatter_example[59120:903] jsonString: '["2011-03-25T11:42:16.175-0400"]' |
82 | 82 | } |
|
90 | 90 | [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"]; |
91 | 91 | ​ |
92 | 92 | jsonString = [array JSONStringWithOptions:encodeOptions |
93 | | - serializeUnsupportedClassesUsingBlock:^id(id object) { |
94 | | - if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); } |
95 | | - return(NULL); |
96 | | - } |
97 | | - error:NULL]; |
| 93 | + serializeUnsupportedClassesUsingBlock:\^id(id object) { |
| 94 | + if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); } |
| 95 | + return(NULL); |
| 96 | + } |
| 97 | + error:NULL]; |
98 | 98 | NSLog(@"jsonString: '%@'", jsonString); |
99 | 99 | // 2011-03-25 11:49:56.434 json_parse[59167:903] jsonString: '["2011-03-25T11:49:56.434-0400"]' |
100 | 100 | } |
|
0 commit comments