I have an HTTP Post request that returns a JSON object. I can view the return value as a string and it is perfect. What I am stuck on is converting this return value into something that can be parsed as a JSON object. I'm not sure of the conceptual steps, much less the code that I should be writing.
Here is the code that I have. It crashes the JSON serialization line because the line before it where I attempt to convert the return string into NSData results in a nil value. Not even sure if I need this step, but I can't find a successful solution.
Can anyone tell me what I am doing wrong? Thanks!
- (void) finished: (NSNotification *) n
{
MyDownloader *d = [n object];
NSData *data = nil;
if ([n userInfo]) {
NSLog(@"information retrieval failed");
} else {
data = d.receivedData;
NSString *text=[[NSString alloc]initWithData:d.receivedData encoding:NSUTF8StringEncoding];
NSLog(@"%@", text);
NSData *data = [NSData dataWithContentsOfFile:text];
self.response = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
if (self.response)
[self parseJSONObject];
else NSLog(@"The server has responded with something other than a JSON formatted object");
}
[[NSNotificationCenter defaultCenter] removeObserver:self
name: @"connectionFinished"
object:d];
}