저는 ios를 처음 사용하며 현재 json에서 작업 중입니다. 난 그냥 테이블보기에 표시 할 수있는 아이튠즈 상위 10 앨범을 사용하여 내가 포맷 및 테이블보기에 표시되는 데이터를 받았지만 앨범 이름 만 표시 할 수 있지만 표시 할 특정 앨범의 모든 세부 사항을 표시하고 싶습니다 같은 세포. 여기 xcode의 테이블보기에서 json 데이터를 표시하는 방법
내 전체 코드 내 출력은 같은 것 잘작업
- (void)viewDidLoad
{
[super viewDidLoad];
albumtop=[[NSMutableArray alloc]init];
[[self itunestTable]setDataSource:self];
[[self itunestTable]setDelegate:self];
NSURL *url=[NSURL URLWithString:@"https://itunes.apple.com/in/rss/topalbums/limit=10/json"];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
connection=[NSURLConnection connectionWithRequest:req delegate:self];
if(connection)
{
albumdata =[[NSMutableData alloc]init];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[albumdata setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[albumdata appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"error in connection");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *alldata =[NSJSONSerialization JSONObjectWithData:albumdata options:0 error:nil];
NSDictionary *album =[alldata objectForKey:@"feed"];
NSArray *total =[album objectForKey:@"entry"];
for(NSDictionary *top in total)
{
NSDictionary *albumname =[top objectForKey:@"im:artist" ];
title =[albumname objectForKey:@"label"];
[albumtop addObject:title];
}
[[self itunestTable]reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [albumtop count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(!cell)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
cell.textLabel.text=[albumtop objectAtIndex:indexPath.row];
return cell;
}
프로그램이
---------------------------------
Jones
---------------------------------------
carry Kim
---------------------------------------
내가 할 수있는 내가 모두를 표시 할 수있는 유일한 방법 단일 값을 가져올 수 이 앨범의 자세한 내용
----------------------------------
Jones
no.tracks 10
price 180
---------------------------------------
carry Kim
no.tracks 10
price 180
---------------------------------------
어떻게 도와 드릴까요? 미리 감사드립니다.
연구 문서를 사용해야합니다. –
(힌트 : 먼저 모든 데이터를 하나의 NSMutableArray에 결합합니다 (예 : 각 행의 NSDictionaries). 그런 다음 배열을 테이블 뷰 대리자 클래스에 전달하면됩니다. –
JSON 구문 분석은 내가 위에서 언급 한 배열에 매우 가깝다. 정확하게는 그렇지 않다. 배열은 모든 것에 중심이다.) (즉, 'total'을 사용하라. 'albumTop'을 사용하지 말라. 당신은 필요하고 엔트리 수 등은 맞습니다. cellForRowAtIndexPath 내부에서 특정 행에 필요한 모든 정보를 추출하기 위해'total'을 참조하십시오.) –