001.
002.
003.
004.
005.
006.
007.
008.
009.
#import "ViewController.h"
010.
011.
@interface
ViewController ()
012.
{
013.
NSMutableArray
*myObject;
014.
015.
016.
NSDictionary
*dict;
017.
018.
019.
NSString
*memberid;
020.
NSString
*name;
021.
NSString
*tel;
022.
}
023.
024.
@end
025.
026.
@implementation
ViewController
027.
028.
- (
void
)viewDidLoad
029.
{
030.
[
super
viewDidLoad];
031.
032.
033.
034.
memberid = @
"MemberID"
;
035.
name = @
"Name"
;
036.
tel = @
"Tel"
;
037.
038.
039.
040.
041.
myObject = [[
NSMutableArray
alloc] init];
042.
043.
NSData
*jsonData = [
NSData
dataWithContentsOfURL:
045.
046.
id
jsonObjects = [
NSJSONSerialization
JSONObjectWithData:jsonData options:
NSJSONReadingMutableContainers
error:
nil
];
047.
048.
049.
for
(
NSDictionary
*dataDict in jsonObjects) {
050.
NSString
*strMemberID = [dataDict objectForKey:@
"MemberID"
];
051.
NSString
*strName = [dataDict objectForKey:@
"Name"
];
052.
NSString
*strTel = [dataDict objectForKey:@
"Tel"
];
053.
054.
dict = [
NSDictionary
dictionaryWithObjectsAndKeys:
055.
strMemberID, memberid,
056.
strName, name,
057.
strTel, tel,
058.
nil
];
059.
[myObject addObject:dict];
060.
}
061.
062.
}
063.
064.
- (
NSInteger
)tableView:(
UITableView
*)tableView numberOfRowsInSection:(
NSInteger
)section
065.
{
066.
return
myObject.count;
067.
}
068.
069.
- (
UITableViewCell
*)tableView:(
UITableView
*)tableView cellForRowAtIndexPath:(
NSIndexPath
*)indexPath
070.
{
071.
072.
static
NSString
*CellIdentifier = @
"Cell"
;
073.
074.
UITableViewCell
*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
075.
if
(cell ==
nil
) {
076.
077.
cell = [[[
UITableViewCell
alloc] initWithStyle :
UITableViewCellStyleSubtitle
078.
reuseIdentifier : CellIdentifier] autorelease];
079.
}
080.
081.
082.
NSDictionary
*tmpDict = [myObject objectAtIndex:indexPath.row];
083.
084.
085.
NSMutableString
*text;
086.
text = [
NSString
stringWithFormat:@
"MemberID : %@"
,[tmpDict objectForKey:memberid]];
087.
088.
089.
NSMutableString
*detail;
090.
detail = [
NSString
stringWithFormat:@
"Name : %@ , Tel : %@"
091.
,[tmpDict objectForKey:name]
092.
,[tmpDict objectForKey:tel]];
093.
094.
cell.textLabel.text = text;
095.
cell.detailTextLabel.text= detail;
096.
097.
098.
099.
100.
return
cell;
101.
}
102.
103.
104.
- (
void
)didReceiveMemoryWarning
105.
{
106.
[
super
didReceiveMemoryWarning];
107.
108.
}
109.
110.
- (
void
)dealloc {
111.
[myTable release];
112.
[
super
dealloc];
113.
}
114.
@end