i know this is a stupid question but i d’ont know how to do that. from this link the requested link is possible to return json data with NSURLconnection ? I hope some one check this link and tell me if is this possible because i am new in this stuff.
EDIT:
i tried with NSJSONSerialization
- (void)viewDidLoad
{
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.goalzz.com/main.aspx?region=-1&area=6&update=true"]];
connectionData = [[NSURLConnection alloc]initWithRequest:req delegate:self];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
Data = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[Data appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *jsonParsingError = nil;
id object = [NSJSONSerialization JSONObjectWithData:Data options:0 error:&jsonParsingError];
if (jsonParsingError) {
NSLog(@"JSON ERROR: %@", [jsonParsingError localizedDescription]);
} else {
NSLog(@"OBJECT: %@", [object class]);
}
}
and I get this error message in the console :
JSON ERROR: The operation couldn’t be completed. (Cocoa error 3840.)
As the comment above suggests, that link doesn’t return JSON. However, assuming you do have such a link, you can use the NSJSONSerialization class to parse JSON data into objective-C classes:
http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40010946
Combine this with NSURLConnection and you can do what you ask. Here’s a walk through on implementing NSURLConnection:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836-BAJEAIEE
And here’s an outline of what you’d need. Obviously this is not working code: