Objective c 从响应中获取参数值
Objective c get parameter values from reposnse
我的回复:
data = {
"user_id" = "1";
username = "dame";
},
messsage = "success";
response = 1;
我的代码:
NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseobject];
NSDictionary *data = [[NSDictionary alloc]initWithDictionary:dict];
int success = [[NSString stringWithFormat:@"%@",dict [@"response"]]intValue];
NSString*userid = [NSString stringWithFormat:@"%@",data [@"user_id"]];
NSLog(@"%@", userid);
我的用户 ID 为空。我不知道 issue.please 帮了我什么。
您错过了父密钥
NSString*userid = [NSString stringWithFormat:@"%@",data ["data"] [@"user_id"]];
试试这个:
NSString*userid = [NSString stringWithFormat:@"%@",[[data valueForKey:@"data"] valueForKey:@"user_id"]];
NSLog(@"%@", userid);
试试这个
NSString *userid = [data valueForKeyPath:@"data.user_id"];
你的数据字典有完整的 responseObject 因为你没有传递 dict["data"],更改那行以获取 userId
NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseobject];
要获取数据,您必须添加 数据 键
NSDictionary *data = [[NSDictionary alloc]initWithDictionary:dict["data"]];
int success = [[NSString stringWithFormat:@"%@",dict [@"response"]]intValue];
NSLog(@"%d", success);
NSString*userid = [NSString stringWithFormat:@"%@",data [@"user_id"]];
NSLog(@"%@", userid);
我的回复:
data = {
"user_id" = "1";
username = "dame";
},
messsage = "success";
response = 1;
我的代码:
NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseobject];
NSDictionary *data = [[NSDictionary alloc]initWithDictionary:dict];
int success = [[NSString stringWithFormat:@"%@",dict [@"response"]]intValue];
NSString*userid = [NSString stringWithFormat:@"%@",data [@"user_id"]];
NSLog(@"%@", userid);
我的用户 ID 为空。我不知道 issue.please 帮了我什么。
您错过了父密钥
NSString*userid = [NSString stringWithFormat:@"%@",data ["data"] [@"user_id"]];
试试这个:
NSString*userid = [NSString stringWithFormat:@"%@",[[data valueForKey:@"data"] valueForKey:@"user_id"]];
NSLog(@"%@", userid);
试试这个
NSString *userid = [data valueForKeyPath:@"data.user_id"];
你的数据字典有完整的 responseObject 因为你没有传递 dict["data"],更改那行以获取 userId
NSDictionary *dict = [[NSDictionary alloc]initWithDictionary:responseobject];
要获取数据,您必须添加 数据 键
NSDictionary *data = [[NSDictionary alloc]initWithDictionary:dict["data"]];
int success = [[NSString stringWithFormat:@"%@",dict [@"response"]]intValue];
NSLog(@"%d", success);
NSString*userid = [NSString stringWithFormat:@"%@",data [@"user_id"]];
NSLog(@"%@", userid);