Skip to content

Commit

Permalink
Use the ChunkParser in the DisplayPretty example
Browse files Browse the repository at this point in the history
  • Loading branch information
stig committed Nov 13, 2013
1 parent d07a5ba commit d6342f6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Examples/DisplayPretty/DisplayPretty/DisplayPrettyController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#import <SBJson/SBJson.h>

@implementation DisplayPrettyController {
SBJsonParser *_parser;
SBJsonWriter *_writer;
SBJsonWriter *writer;

IBOutlet NSTextField *_source;
IBOutlet NSTextField *_formatted;
Expand All @@ -21,23 +20,22 @@ - (id)init
{
self = [super init];
if (self) {
_parser = [[SBJsonParser alloc] init];
_writer = [[SBJsonWriter alloc] init];
_writer.humanReadable = YES;
_writer.sortKeys = YES;
writer = [[SBJsonWriter alloc] init];
writer.humanReadable = YES;
writer.sortKeys = YES;
}
return self;
}


- (IBAction)formatText:(id)sender {
id object = [_parser objectWithString:[_source stringValue]];
if (object) {
[_formatted setStringValue:[_writer stringWithObject:object]];
} else {
[_formatted setStringValue:[NSString stringWithFormat:@"An error occurred: %@", _parser.error]];
}
id parser = [[SBJsonChunkParser alloc] initWithBlock:^(id o, BOOL *stop) {
_formatted.stringValue = [writer stringWithObject:o];
} errorHandler:^(NSError*err) {
_formatted.stringValue = [err localizedDescription];
}];

[parser parse:[_source.stringValue dataUsingEncoding:NSUTF8StringEncoding]];
}

@end

0 comments on commit d6342f6

Please sign in to comment.