root / json-framework-3.2.0 / Examples / DisplayPretty / DisplayPretty / DisplayPrettyController.m @ 3ebe9884
History | View | Annotate | Download (926 Bytes)
1 |
// |
---|---|
2 |
// DisplayPrettyController.m |
3 |
// DisplayPretty |
4 |
// |
5 |
// Created by Stig Brautaset on 25/05/2011. |
6 |
// Copyright 2011 Stig Brautaset. All rights reserved. |
7 |
// |
8 |
|
9 |
#import "DisplayPrettyController.h" |
10 |
#import <SBJson/SBJson.h> |
11 |
|
12 |
@implementation DisplayPrettyController |
13 |
|
14 |
- (id)init |
15 |
{ |
16 |
self = [super init]; |
17 |
if (self) { |
18 |
_parser = [[SBJsonParser alloc] init]; |
19 |
_writer = [[SBJsonWriter alloc] init]; |
20 |
_writer.humanReadable = YES; |
21 |
_writer.sortKeys = YES; |
22 |
} |
23 |
return self; |
24 |
} |
25 |
|
26 |
- (void)dealloc |
27 |
{ |
28 |
[_parser release]; |
29 |
[_writer release]; |
30 |
[super dealloc]; |
31 |
} |
32 |
|
33 |
- (IBAction)formatText:(id)sender { |
34 |
id object = [_parser objectWithString:[_source stringValue]]; |
35 |
if (object) { |
36 |
[_formatted setStringValue:[_writer stringWithObject:object]]; |
37 |
} else { |
38 |
[_formatted setStringValue:[NSString stringWithFormat:@"An error occurred: %@", _parser.error]]; |
39 |
} |
40 |
|
41 |
} |
42 |
|
43 |
@end |