Я пробовал это несколько раз, и я до сих пор не понимаю, как войти в канал JSON и получить то, что мне нужно, чтобы захватить.Json Iphone Parse Data
Feed выглядит так, в моем коде я пытаюсь вытащить все заголовки. Я не знаю, как спуститься в Json Feed.
- (void)viewDidLoad
{
[super viewDidLoad];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURL *url = [NSURL URLWithString:@"http://api.storageroomapp.com/accounts/511a4f810f66026b640007b8/collections/511a51580f66023bff000ce9/entries.json?auth_token=Zty6nKsFyqpy7Yp5DP1L&preview_api=1"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
// Do any additional setup after loading the view from its nib.
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
data = [[NSMutableData alloc] init];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData{
[data appendData:theData];
}
-(void)connectionDidFinishLoading:(NSURLConnection *) connection{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
[mainTableView reloadData];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The data could not be downloaded - please make sure you're connected to either 3G or Wi-FI" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(int)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [news count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];
cell.textLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"title"];
}
return cell;
}
и В моей .H я есть NSArray * новости; и данные NSMutableData *.
Любая помощь была бы замечательной, не могли бы вы объяснить свое само собой разумеющееся, так как я новичок на этом языке.
Hi Если я загружу почтовый индекс, вы можете быстро взглянуть, и ему трудно следовать. – Brent
Ну, посмотрите, где вы разбираете словарь и настраиваете его на то, что я сказал в своем посте. Наконец, я также укажу вам на метод и логику, необходимые для доступа к названию. Дайте ему пойти и ответьте, если у вас возникнут проблемы. –
Извините, я не понимаю, что последний бит? – Brent