Parse JSON response with AFNetworking
afnetworking, ios, json, objective-c, xcode5
Solution
`responseObject` is either an NSArray or NSDictionary. You can check at runtime using `isKindOfClass:`:
if ([responseObject isKindOfClass:[NSArray class]]) {
NSArray *responseArray = responseObject;
/* do something with responseArray */
} else if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *responseDict = responseObject;
/* do something with responseDict */
}
If you really need the string of the JSON, it's available by looking at `operation.responseString`.
Problem
I've setup a JSON post with `AFNetworking` in Objective-C and am sending data to a server with the following code: ``` AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"name": deviceName, @"model": modelName, @"pin": pin}; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setValue:@"Content-Type" forHTTPHeaderField:@"application/json"]; [manager POST:@"SENSORED_OUT_URL" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; ``` I'm receiving information through the same request, and want to send the data to a `NSString`. How would I go about doing that with `AFNetworking`?