iossigabrtjsonkit

getting error when calling objectFromJSONString using JSONKit


I use the following code to create a dictionary based on a JSON string received from the server. (I have downloaded JSONKit and embedded it into the project). The code below returns a legal JSON string from the server (parsed well on Android) but crashes when I try to convert it to a dictionary.

- (IBAction)submit
{
bool useSSL = true;
char *c_url="http://(rest of URL)";


NSString* url = [NSString stringWithFormat:@"%s" , c_url];
url = [NSString stringWithFormat:@"%@%@%s", url, self.label.text, "/keys"];
NSString * response = [self getDataFrom:url];


NSDictionary *dict = [response objectFromJSONString]; //generates SIGABRT!!
NSLog(@"%@",dict); 

NSString *success = [dict valueForKey:@"success"];

} 



- (NSString *) getDataFrom:(NSString *)url{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:url]];

NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;

NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];

if([responseCode statusCode] != 200){
    NSLog(@"Error getting %@, HTTP status code %i", url, [responseCode statusCode]);
    return nil;
}

return [[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding]; 
}

THANKS, Simon


Solution

  • Found an answer here. Answer says: "Figured it out... I had JSONKIt.h included in the project but for some weird reason, JSONKit.m was not included in the 'Compile Sources' under 'Build Phases' - once I added it manually it started working fine."