我目前正在尝试发布一个php web服务,它将查询一个mysql数据库并且[应该]返回一个字符串值。我已经研究过AFNetworking但是不了解如何使用从查询返回的值。例如:
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来获取我想要的字符串?任何帮助将不胜感激
答案 0 :(得分:1)
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