Ich versuche, JSON-Daten zu holen und analysiere es NSURL Sitzung verwenden, aber jedes Mal, null bekommen - auch zusätzlich zu dem, i o zeigen will, dass alle Daten in der TabellenansichtWie Daten mit NSUrl-Sitzung in Objective-C abrufen?
NSError *error;
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURL *url = [NSURL URLWithString:@"https://dl.dropboxusercontent.com/s/2iodh4vg0eortkl/facts.json"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue:@"text/plain" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"text/plain" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"GET"];
NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"Value", @"Key", nil];
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
[request setHTTPBody:postData];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Resopnse == %@",response);
if (response != nil) {
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"JSon dict === %@",jsonDict);
}
}];
[postDataTask resume];
ich etwas wissen Darf ich falsch machen ist alles andere eine gute Möglichkeit, dasselbe zu tun?
Was ist null? Antwort? "Daten"? 'jsonDict'? Normalerweise setzen Sie keine Parameter für GET in HTTPBody. – Larme