I am trying to get JSON data from this API, but I get error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x8b5aa20 {NSDebugDescription=Invalid value around character 0.}
Here is the code:
NSString *post = [NSString stringWithFormat:@"http://api.reittiopas.fi/hsl/1_1_2/?request=reverse_geocode&user=********&pass=********&format=txt&coordinate=2548196,6678528"];
NSError *error = nil;
NSString* newStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:post] encoding:NSUTF8StringEncoding error: &error];
NSData *jsonDataString = [newStr dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonDataString.description);
NSMutableDictionary *allResults = [NSJSONSerialization
JSONObjectWithData:jsonDataString
options:NSJSONReadingAllowFragments
error:&error];
if(!error){
NSLog(@"%@", allResults.description);
}
else{
NSLog(@"%@", error.description);
}
Can anyone tell me why I am getting this error. The code is working with other web's JSON data.
[NSData dataWithContentsOfUrl:...]
– k06aformat=txt
toformat=json
in your API address. I tested it, it'll work fine – Julian F. Weinert