gpt4 book ai didi

ios - 从服务 Objective-C 获取数据

转载 作者:行者123 更新时间:2023-11-29 00:26:59 25 4
gpt4 key购买 nike

我是 iOS 新手,在显示来自以下服务数据的数据时遇到问题

[{
"Name": Rahul,
"FatherName": Ravinder,
"Designation": Engineering,
"Profession": Software Eng,
"Height": "5 ft 3 in",
"Weight": "134.5 lbs"
}]

下面是我试过的代码。请帮我找出问题所在。提前致谢。

 NameDetails.m
---------------

- (void)viewDidLoad {
[super viewDidLoad];
[self callService:[appDelegate.signUpdata objectForKey:@"id"]];
}

-(void)callService:(NSString *)userid
{
[Utility showIndicator:nil view1:self.view];
JsonServicePostData = [[JsonServiceCls alloc] init];
JsonServicePostData.delegate = self;
[JsonServicePostData Getdata:userid];
}

-(void)DidFinishWebServicesPostData
{
[Utility hideIndicator];

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
_txtName.text=[dict objectForKey:@"Name"];
_txtFName.text=[dict objectForKey:@"FatherName"];
_txtDesg.text=[dict objectForKey:@"Designation"];
_txtprof.text=[dict objectForKey:@"Profession"];
_txtHeight.text=[dict objectForKey:@"Height"];
_txtWeight.text=[dict objectForKey:@"Weight"];

}

}

最佳答案

+(void)makeHttpGETresponceParsingwithSerVer:(NSString *)strServer withCallBack:(void(^)(NSDictionary *dicArr,NSError *error))handler
{

NSURL *urlServer = [NSURL URLWithString:strServer];

NSURLRequest *request = [NSURLRequest requestWithURL:urlServer];

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

NSDictionary *res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];


handler(res,error);


}];

[postDataTask resume];
}
then call your method In viewDidLoad...

[RestClient makeHttpGETresponceParsingwithSerVer:@"YOUR_URL" withCallBack:^(NSDictionary *responceDic, NSError *error) {

_txtName.text =[responceDic objectForKey:@"Name"];
_txtFName.text =[responceDic objectForKey:@"FatherName"];
_txtDesg.text =[responceDic objectForKey:@"Designation"];
_txtprof.text =[responceDic objectForKey:@"Profession"];
_txtHeight.text =[responceDic objectForKey:@"Height"];
_txtWeight.text =[responceDic objectForKey:@"Weight"];

}];

//RestClient是类名,因为它是类方法,可以使用实例方法。

关于ios - 从服务 Objective-C 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42732098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com