iOS AFNetworking post 麻烦
iOS AFNetworking post troubles
我目前正在尝试 post 到 php Web 服务,该服务将查询 mysql 数据库并且 [应该] return 具有字符串值。我查看了 AFNetworking,但不明白如何使用查询中 returned 的值。例如:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://samwize.com/api/poo/"
parameters:@{@"color": @"green"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
我猜我是在操纵 responseObject 来获取预期的字符串?任何帮助将不胜感激
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://samwize.com/api/poo/"
parameters:@{@"color": @"green"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *error = nil;
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
if (error) {
NSLog(@"Error serializing %@", error);
}
NSLog(@"JSON: %@", JSON);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
这会将您的 JSON
回复转换为 NSDictionary
我目前正在尝试 post 到 php Web 服务,该服务将查询 mysql 数据库并且 [应该] return 具有字符串值。我查看了 AFNetworking,但不明白如何使用查询中 returned 的值。例如:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://samwize.com/api/poo/"
parameters:@{@"color": @"green"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
我猜我是在操纵 responseObject 来获取预期的字符串?任何帮助将不胜感激
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://samwize.com/api/poo/"
parameters:@{@"color": @"green"}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *error = nil;
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
if (error) {
NSLog(@"Error serializing %@", error);
}
NSLog(@"JSON: %@", JSON);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
这会将您的 JSON
回复转换为 NSDictionary