我使用以下代码从Drupal数据库中检索数据到我的iOS应用程序:
·H
@property (strong, nonatomic) NSMutableArray *userData;
的.m
self.userData = [NSMutableArray new];
NSMutableDictionary *viewParams = [NSMutableDictionary new];
[viewParams setValue:@"u000" forKey:@"view_name"];
[DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.userData = [responseObject mutableCopy];
NSLog(@"%@",self.userData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
self.userData = [[NSMutableArray alloc] init];
self.userBio.text = self.userData[0][@"userbio"];
填充了self.userData,因此我知道我的数据已成功返回。有谁知道如何在UIlabel中显示JSON返回的字段?我只是不确定如何编写这行代码(newb,抱歉)。我的字段名称是 userbio 。
更新: NSLog(@"userData = %@", self.userData);
在控制台中返回此信息:
2015-10-25 11:22:06.601 [7605:2738034]
userData = (
> {
> userbio = "No user bio available at this time.";
> "users_name" = "<a href=\"/user/20\" title=\"View user profile.\" class=\"username\" xml:lang=\"\" about=\"/user/20\"
> typeof=\"sioc:UserAccount\" property=\"foaf:name\"
> datatype=\"\">Brittany</a>";
> },
答案 0 :(得分:0)
如果它是NSDictionary,代码将如下所示:
self.myLabelName.text = self.userData[@"userbio"];
如果它是NSDictionary的NSArray,它看起来像:
self.myLabelName.text = [self.userData firstObject][@"userbio"];
假设数组只包含一个字典,否则你必须访问每个元素:self.userData [0],self.userData [1]等。