From ab0c357216564967ccbb900923ead3830a13752b Mon Sep 17 00:00:00 2001 From: matt handler Date: Mon, 25 Apr 2011 02:21:36 -0400 Subject: added json stuff, sources are loading but not connected to any sensical database or nothing... coming together. next hard bit is going to be the animation when things update --- .../CJSONDeserializer_BlocksExtensions.m | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Classes/Source/Experimental/CJSONDeserializer_BlocksExtensions.m (limited to 'Classes/Source/Experimental/CJSONDeserializer_BlocksExtensions.m') diff --git a/Classes/Source/Experimental/CJSONDeserializer_BlocksExtensions.m b/Classes/Source/Experimental/CJSONDeserializer_BlocksExtensions.m new file mode 100644 index 0000000..7ea774c --- /dev/null +++ b/Classes/Source/Experimental/CJSONDeserializer_BlocksExtensions.m @@ -0,0 +1,63 @@ +// +// CJSONDeserializer_BlocksExtensions.m +// TouchJSON +// +// Created by Jonathan Wight on 10/15/10. +// Copyright 2010 toxicsoftware.com. All rights reserved. +// + +#import "CJSONDeserializer_BlocksExtensions.h" + +#import "CJSONScanner.h" + +@implementation CJSONDeserializer (CJSONDeserializer_BlocksExtensions) + +- (void)deserializeAsDictionary:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block { + + NSError *noDataError = nil; + if (inData == NULL || [inData length] == 0) { + noDataError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:kJSONScannerErrorCode_NothingToScan userInfo:NULL]; + block(nil, noDataError); + } + + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + + NSError *deserializationError = nil; + self.scanner.data = inData; + NSDictionary *theDictionary = NULL; + BOOL successful = [self.scanner scanJSONDictionary:&theDictionary error:&deserializationError]; + + dispatch_async(dispatch_get_main_queue (), ^{ + if (successful) + block(theDictionary, nil); + else + block(nil, deserializationError); + }); + }]; +} + +- (void)deserializeAsArray:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block { + + NSError *nullInDataError = nil; + if (inData == NULL || [inData length] == 0) { + nullInDataError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:kJSONScannerErrorCode_NothingToScan userInfo:NULL]; + block(nil, nullInDataError); + } + + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + + NSError *deserializationError = nil; + self.scanner.data = inData; + NSArray *theArray = NULL; + BOOL successful = [self.scanner scanJSONArray:&theArray error:&deserializationError]; + + dispatch_async(dispatch_get_main_queue(), ^{ + if (successful) + block(theArray, nil); + else + block(nil, deserializationError); + }); + }]; +} + +@end -- cgit v1.2.3