嗨,我这里有这段代码
- (void)viewDidLoad
{
[super viewDidLoad];
jsonURL = [NSURL URLWithString:@"http://oo.mu/json.php"];
jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL usedEncoding:nil error:nil];
self.jsonArray = [jsonData JSONValue];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *jsonObject = [parser objectWithString:jsonData error:NULL];
NSArray *list = [jsonObject objectForKey:@"Dewan's Party"];
for (NSDictionary *lesson in list)
{
// 3 ...that contains a string for the key "stunde"
NSString *content = [lesson objectForKey:@"Street"];
NSLog(@"%@", content);
}
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [jsonArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
return cell;
}
我正在使用这个 JSon.php 文件。
{"Steffan's Party":{"Street":"774 Hoodwinked Avenue","City":"Sacramento","State":"California"},"Dewan's Party":{"Street":"2134 Statewide Lane","City":"New York","State":"New York"},"Austin's Party":{"Street":"9090 Gravink Court","City":"Woodland","State":"California"}}
这是网站http://oo.mu/json.php的链接。
我在这里要做的是解析它自己的 UITableView 单元格中的每个数组。下面的示例,我该怎么做?
表格单元格 1:Steffan 的派对 774 Hoodwinked Ave Sacramento, California
表格单元格 2:Dewan 的派对 2134 Statewide Lane New York, New York
我怎样才能做到这一点?