我的朋友为我的应用写了一个服务。这是链接http://213.155.113.51/cronos/medconcept/services/v3/iOSServices.svc/productsget
,这是测试链接。我只想尝试串。我试过这篇文章http://www.codeproject.com/Tips/569495/Creating-a-WCF-Service-with-JSON-Data-and-Using-it,但Json来了null
以下是我的代码的一部分;
NSString *request = [NSString stringWithFormat:@"link here"];
NSURL *URL = [NSURL URLWithString:
[request stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:URL options:NSDataReadingUncached error:&error];
NSLog(@"data = %@",data);
if(!error)
{
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
NSLog(@"Json = %@",json);
NSMutableArray *array= [json objectForKey:@"GetUserResult"];
NSLog(@"array = %@",array);
/*
for(int i=0; i< array.count; i++)
{
NSDictionary *userInfo= [array objectAtIndex:i];
NSInteger *id = [userInfo objectForKey:@"ID"];
NSString *name = [userInfo objectForKey:@"NAME"];
NSString *surname = [userInfo objectForKey:@"SURNAME"];
NSLog(@"ID: %d NAME: %@ SURNAME: %@", id,name,surname);
}
*/
}
输出:Json =(null) array =(null)
我做错了什么?或者你知道获取和发布字符串的替代方法吗?
感谢您的关注和建议。