Objective c 目标c解析从wcf服务返回json
所以我最近问了这个问题,我能让它起作用 这是我的密码Objective c 目标c解析从wcf服务返回json,objective-c,wcf,wcf-data-services,nsjsonserialization,Objective C,Wcf,Wcf Data Services,Nsjsonserialization,所以我最近问了这个问题,我能让它起作用 这是我的密码 NSString *urlStringRequest = [NSString stringWithFormat:@"http://service.mydomain.com/UserAccountService.svc/UserLogin?id=%@&pword=%@", email, incPassword]; NSMutableURLRequest *request = [NSMutableURLRequest requ
NSString *urlStringRequest = [NSString stringWithFormat:@"http://service.mydomain.com/UserAccountService.svc/UserLogin?id=%@&pword=%@", email, incPassword];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStringRequest]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
id jsonResult = [self parseJsonResult:result];
NSLog(@"Json Result Woop: %@", jsonResult);
parseJsonResult与链接上的结果完全相同。但我的问题是,每当我在NSLog上显示jsonResult时,它都会显示json结果,即:
Json Result Woop: {
Authenticated = 0;
Message = "Invalid Log In.";
}
但我不确定如何进入变量并逐个检索键及其值
我试着这样做:
NSError *jsonParseError = nil;
NSMutableArray *jsonArray = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments error:&jsonParseError];
if(!jsonArray)
NSLog(@"Parse error: %@", jsonParseError);
else
for(NSDictionary *item in jsonArray)
NSLog(@"%@", item);
使用结果变量,但它只会给我键
不太确定该怎么办。JsonResult已经是一本NSDictionary了,NSLog用大括号显示了它。只用
jsonResult[@"Message"]
要获取消息键的值。hii,请告诉我如何成功调用wcf web服务。我尝试了您的代码以及您引用的minthos代码,但我无法从代码调用wcf。。请帮我做这件事。