stig/json-framework — pull request #182 by brycepauken (2013-10-29 00:32:56+00:00)
Title: Add option to process values as they’re parsed

Changes
------------

This would add/expose two new methods to SBJsonParser:

- (id)objectWithData:(NSData *)data processValuesWithBlock:(id (^)(id))processBlock;
- (id)objectWithString:(NSString *)string processValuesWithBlock:(id (^)(id))processBlock;

Both are extensions of the two original methods, which allow values to be processed using a given block.

I'm now using these methods in a project of mine (rather than the previous process of recursively iterating through the returned object to change values), and it's understandably much more time/computation efficient for large inputs- I figured it might be useful to a few other users who need to do things like decoding HTML entities (that's me!), capitalizing strings, averaging numbers, or whatever else may be needed.

Oh, and all original function definitions are still in place, so any particularly roundabout changes others have made would still run fine :)

Example/Testing
------------------------

As a simple example, this code would create a parsed version of `jsonInput`, but with all strings capitalized:

id response = [self.parser objectWithString:jsonInput processValuesWithBlock:^ id(id obj) {
if([obj respondsToSelector:@selector(uppercaseString)])
return [obj uppercaseString];
else
return obj;
}];