01.
02.
03.
04.
05.
06.
07.
08.
09.
#import "ViewController.h"
10.
11.
#import "DetailController.h"
12.
13.
@interface
ViewController ()
14.
15.
@end
16.
17.
@implementation
ViewController
18.
19.
- (
void
)viewDidLoad
20.
{
21.
[
super
viewDidLoad];
22.
23.
}
24.
25.
- (
void
)didReceiveMemoryWarning
26.
{
27.
[
super
didReceiveMemoryWarning];
28.
29.
}
30.
31.
- (
IBAction
)btnSubmit:(
id
)sender {
32.
33.
NSMutableDictionary
*element = [
NSMutableDictionary
dictionary];
34.
[element setObject:[txtName text] forKey:@
"Name"
];
35.
[element setObject:[txtTel text] forKey:@
"Tel"
];
36.
[element setObject:[txtEmail text] forKey:@
"Email"
];
37.
NSData
*jsonData = [
NSJSONSerialization
dataWithJSONObject:element
38.
options:
NSJSONWritingPrettyPrinted
39.
error:
nil
];
40.
NSLog
(@
"jsonData= %@"
,jsonData);
41.
42.
NSString
* jsonCode = [[[
NSString
alloc] initWithData:jsonData
43.
encoding:
NSUTF8StringEncoding
] autorelease];
44.
NSLog
(@
"jsonCode= %@"
,jsonCode);
45.
46.
DetailController *view2 = [[[DetailController alloc] initWithNibName:
nil
bundle:
nil
] autorelease];
47.
view2.json = jsonCode;
48.
[
self
presentViewController:view2 animated:
NO
completion:
NULL
];
49.
}
50.
51.
- (
void
)dealloc {
52.
[txtName release];
53.
[txtTel release];
54.
[txtEmail release];
55.
[
super
dealloc];
56.
}
57.
58.
@end