Skip to content

Instantly share code, notes, and snippets.

@mschulkind
Created December 2, 2011 04:34
Show Gist options
  • Save mschulkind/1421772 to your computer and use it in GitHub Desktop.
Save mschulkind/1421772 to your computer and use it in GitHub Desktop.
// Construct and run the javascript. SBJsonParser only works with objects or
// arrays, so we wrap the result in an array in case the result is not either
// an object or an array.
NSString* wrappedJavascript =
[NSString stringWithFormat:@"JSON.stringify([%@])", javascript];
NSString* resultJSON = [componentPlugin writeJavascript:wrappedJavascript];
// Parse and return the result, making sure to unwrap the result first.
SBJsonParser* jsonParser = [[[SBJsonParser alloc] init] autorelease];
NSArray* wrappedResult = [jsonParser objectWithString:resultJSON];
return [wrappedResult objectAtIndex:0];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment