I have the following code with the following errors and I am not sure what I am doing wrong:
NSDictionary *jsonDict = [NSDictionary dictionaryWithObjectsAndKeys: @"init", @"method", nil];
NSString *requestString = [NSString stringWithFormat:@"json=%@", [jsonDict JSONFragment], nil];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://exampleurl.com/json.php"]];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: requestData];
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSLog(@"Returned Json: %@", returnString);
I get the following error before running Instance Method '-JSONFragment' not found(return type defaults to 'id') which suggests that I have not added all the correct files from SBJSON, but all the files are there.
When I run the application I get the following error message:
-[__NSCFDictionary JSONFragment]: unrecognized selector sent to instance 0x4e99010
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary JSONFragment]: unrecognized selector sent to instance 0x4e99010'
I have no idea what I am doing wrong, any suggestions?
My version of SBJson doesn’t have a method called JSONFragment. This is how I turn a dictionary into a Json formatted request string.