我正在使用AFnetworking 3.0进行XML解析。 以下是我的代码。
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:Username, @"username", pass, @"password",device,@"device",token,@"devicetoken", nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/soap+xml" forHTTPHeaderField:@"Content-Type"];
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:[NSString stringWithFormat:@"https://xyz.or/webservice.php"] parameters:dict error:nil];
req.timeoutInterval= [[[NSUserDefaults standardUserDefaults] valueForKey:@"timeoutInterval"] longValue];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[req setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (!error) {
NSLog(@"Reply JSON: %@", responseObject);
if ([responseObject isKindOfClass:[NSDictionary class]]) {
//blah blah
}
} else {
NSLog(@"Error: %@, %@, %@", error, response, responseObject);
}
}] resume];
现在我在nsinline数据中获得响应。
JSON: <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d227574 662d3822 3f3e3c41 72726179 3e3c4469 633e3c49 643e202d 31203c2f 49643e3c 2f446963 3e3c2f41 72726179 3e>
任何人都可以告诉我应该怎样做才能获得da
答案 0 :(得分:0)
您需要更改此行
manager.requestSerializer = [AFJSONRequestSerializer serializer];// remove this if no use
manager.requestSerializer = [AFHTTPRequestSerializer serializer]; // remove this if no use
更改
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
使用
manager.responseSerializer = [AFJSONResponseSerializer serializer];