我使用的是用于显示个人和个人资料详情的网络服务,但我不知道如何将数据从网络服务显示到标签。我使用Web服务进行登录验证,代码如下
-(IBAction)login:(id)sender
{
NSString *username=userName.text;
NSString *password=passWord.text;
if ([username length]!=0&&[password length]!=0)
{
NSString *link=[NSStringstringWithFormat:@"http://www.abcd.com/XXX/YYY/Login.ashx/?Username=%@&Password=%@",username,password];
NSURL *URLGet= [NSURL URLWithString:link];
NSData* data = [NSData dataWithContentsOfURL:URLGet];
NSError* error;
XYZ Return array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if ([jasonReturnArray isEqual: @"UserId 4"])
{
Connections *view2=[[Connections alloc]initWithNibName:nil bundle:nil];
view2.modalTransitionStyle= UIModalTransitionStyleFlipHorizontal;
[self presentViewController:view2 animated:NO completion:nil];
NSLog(@"%@",jasonReturnArray);
}
else
{
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"ERROR !!!!!!"message:@"Wrong Details" delegate:self cancelButtonTitle:@"Ok"otherButtonTitles: nil];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"%@",jasonReturnArray);
[alert show];
}
}
else
{
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"ERROR !!!!!!"
message:@"Wrong Details" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"%@",jasonReturnArray);
[alert show];
}
}
它工作正常,但我怀疑是
如何将数据从json网络服务显示到我设计的标签
答案 0 :(得分:1)
创建UILabel的IBOutlet,然后将标签的文本值设置为以下
for (NSString * singleStringObject in jasonReturnArray)
{
yourLabel.text=[yourLabel.text stringByAppendingString:singleStringObject];
}
如果是单个字符串,您只需设置yourLabel
的文本而不进行任何循环。