0
我試圖使用AFNetworking
2.0消耗簡單JSON,從JSON結果是:AFNetworking 2.0和簡單的JSON
{
"solicitudId": "61898",
"estado": "Atendida",
"tipoPago": null,
"monto": 23,
"mayorDerecho": 0,
"sistema": "SPRL"
}
予定義的類(solicitud.h solicitud.m)所示:
@interface SolicitudNSDictionary : NSDictionary
- (NSString *)solicitudId;
- (NSString *)estado;
- (NSString *)tipoPago;
- (NSNumber *)monto;
- (NSNumber *)mayorDerecho;
- (NSString *)sistema;
@end
的JSON是叫這裏沒有錯誤
- (IBAction)jsonButton:(id)sender {
// 1
NSString *string = [NSString stringWithFormat:@"%@solicitud?id=61898&from=MOVIL&ip=172.9.1.14", BaseURLString];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 2
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// 3
self.solicitud = (NSDictionary *)responseObject;
self.title = @"JSON Retrieved";
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// 4
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
// 5
[operation start];
}
@end
我的問題是我不知道如何實現的tableview從NSDictionary,在cellForRowAtIndexPath我試過,但我沒有運氣。
我在@interface
@property(strong) NSDictionary *solicitud;
聲明,該變量在這裏設置
// 3
self.solicitud = (NSDictionary *)responseObject;
我在哪裏得到的錯誤是
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cellName";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *solicitudTmp = nil;
solicitudTmp = [self.solicitud];
// You will add code here later to customize the cell, but it's good for now.
cell.textLabel.text = [self.solicitudTmp solicitudId];
return cell;
}
在這條線
solicitudTmp = [self.solicitud];
你的問題沒有任何意義。什麼不工作? 「我不知道如何從NSDictionary實現tableview」是什麼意思?你所顯示的代碼與你的問題有什麼關係? – 2014-09-30 20:04:56