GregH
GregH

Reputation: 5459

iOS AFNetworking post troubles

I am currently trying to post to a php web service which will query a mysql database and [should] return with a string value. I have looked into AFNetworking but do not understand how to use the value which is returned from the query. for example:

 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);
}];

I am guessing I manipulate responseObject to get my expected string? Any help would be appreciated

Upvotes: 2

Views: 126

Answers (1)

Vig
Vig

Reputation: 1522

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);
              }];

This will convert your JSON response to NSDictionary

Upvotes: 1

Related Questions