[英]Get specific value from NSMutableArray
I'm parsing an XML and saving result to NSMutableArray. 我正在解析XML并将结果保存到NSMutableArray。 When I do NSLog, 当我做NSLog时
NSLog(@"Data : %@",_data);
I'm getting 我越来越
Data : (
{
SessionToken = 9e72dd029e0e8268380b919356881935;
}
)
I only want 9e72dd029e0e8268380b919356881935 from the array. 我只想要阵列中的9e72dd029e0e8268380b919356881935。 What is the best solution to achieve this? 实现此目标的最佳解决方案是什么?
EDIT : There will be only one SessionToken at a time. 编辑:一次将只有一个SessionToken。
You can try this code : 您可以尝试以下代码:
for (NSDictionary *data1 in _data) {
NSlog("session token %@",[data1 objectForKey:@"SessionToken"]);//Other wise add into another array which contain session token.. only..
}
Since there will be only one session at a time. 因为一次将只有一个会话。
NSDictionary *session = [_data lastObject];
NSString *sessionToken = session[@"SessionToken"];
OR with literals 或与文字
NSString *sessionToken = _data[0][@"SessionToken"];
if ([_data count]) {
NSDictionary *dic = [_data objectAtIndex:0];
NSLog(@"Data : %@",[dic objectForKey:@"SessionToken"]);
}
for (NSDictionary *data1 in _data) {
NSlog("session token %@",[data1 valueForKey:@"SessionToken"]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.