I have successfully created a method which connects to my web service and POSTS a string and receives a string response. However, I am now trying to POST a JSON dictionary created using NSJSONSerialization. However, Xcode is giving me an error. I have tried to convert my initial code. Relevant lines below...
NSData* loginDataJSON = [NSJSONSerialization dataWithJSONObject:loginDataDictionary options:NSJSONWritingPrettyPrinted error:&error];
[request setValue:loginDataJSON forHTTPHeaderField:@"loginDataJSON"];
[request setHTTPBody:[loginDataJSON dataUsingEncoding:NSUTF8StringEncoding]];
The second line heres complains that I am using NSData where an NSString is required.
The third line complains that loginDataJSON
may not respond to dataUsingEnconding
I seem to be forcing an NSData object (because that what NSJSONSerialization gives me) where it cannot be used. Am I best trying to convert the JSON into a string to use with my existing request code, or should/can I change my request code to accept NSData as opposed to an NSString?