NSString *URL = @"http://192.168.1.107:8080/ws_Test.asmx/Add"; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml"]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; params[@"a"] = @"123"; params[@"b"] = @"4"; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager POST:URL parameters:params progress:^(NSProgress * _Nonnull uploadProgress){ } success:^(NSURLSessionDataTask *task, id responseObject) { NSString *result = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"%@",result); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"%@",error); //这里打印错误信息 }];}
webservice返回的是:
<?xml version=”1.0″ encoding=”UTF-8″?>
<string xmlns=”http://tempuri.org/”>{ “Code”: “13” }</string>
本人想在ios程序里面判断code的值是多少,当code为1时输出“c=1”,当code为2时输出“c=2”之类的,问一下这个该怎么写?谢谢
解决方案
20
使用iOS请求WebServices的方法吧,然后再解析json