【问题标题】:Unable to parse JSON to UITableView无法将 JSON 解析为 UITableView
【发布时间】:2014-10-28 04:28:27
【问题描述】:

目前我正在尝试解析responseObject 以填充我的表格视图,但我在解析responseObject 中的数组时遇到了一些问题。我想用来自responseObject[@"test"] 的值填充我的单元格。

请求操作:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:[kBaseURL stringByAppendingString:@"directori/member_list"]parameters:params
      success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSLog(@"RESPONSE: %@", responseObject);
          if ([responseObject[@"status_reason"] isEqualToString:@"Success"]) {
              self.allMembers = responseObject[@"test"];
              NSLog(@"MEMBERS: %@", self.allMembers);
          } else {
              // handle error
          }
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"ERROR: %@", error);
      }];

如下所示,test 是一个对象数组。

示例响应对象:

RESPONSE: {
    test =     (
                {
            img = "http://test.com/assets_api/images/no_image.png";
            location = "test location";
            name = "test user";
            position = "test";
        }
    );
    "audit_no" = "";
    "status_code" = 200;
    "status_reason" = Success;
}

这是我的表格视图数据源。

表格视图数据源

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"DirectoryCell";
    DirectoryViewCell *cell = (DirectoryViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell==nil) {
        cell = [[DirectoryViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSDictionary *member = [self.allMembers objectAtIndex:indexPath.row];
    NSLog(@"MEMBER: %@", member);
    return cell;
}

allMembersNSArray 类型,而 memberNSDictionary 类型。 当我尝试记录 member 的值时,它返回 null。哪里出错了?

【问题讨论】:

    标签: objective-c uitableview nsdictionary afnetworking afnetworking-2


    【解决方案1】:

    你应该试试这个

    NSDictionary *member = [[self.allMembers objectAtIndex:indexPath.row]objectAtIndex:0];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-09
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多