OGeek|极客世界-中国程序员成长平台

标题: iOS AFNetworking 发布问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 06:32
标题: iOS AFNetworking 发布问题

我目前正在尝试发布到一个 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 来得到我期望的字符串?任何帮助将不胜感激



Best Answer-推荐答案


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

关于iOS AFNetworking 发布问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29807696/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4