0
我已經嘗試了這幾次,我仍然沒有得到如何進入JSON供稿並檢索我需要抓取的內容。Json Iphone解析數據
飼料看起來像這樣,在我的代碼我試圖拉出所有的標題。我不知道如何進入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 *數據。
任何幫助都會很棒,你能否清楚地解釋你的自我,因爲我是這個語言的全新手。
嗨,如果我上傳的zip可以快速查找,發現它很難遵循。 – Brent 2013-02-12 17:15:45
好吧,看看你在解析字典,並根據我在帖子中說的來調整它。最後,我還指出你需要訪問標題的方法和邏輯。給它一個去,如果你有任何問題,迴應。 – 2013-02-12 17:24:46
對不起,我不明白最後一點? – Brent 2013-02-12 17:28:49