objective c parse json from url request

前端 未结 7 1146
醉酒成梦
醉酒成梦 2021-02-06 00:14

I am trying to parse a json string requested from an api located at: http://www.physics.leidenuniv.nl/json/news.php

However, i am having trouble parsing this json. I get

7条回答
  •  梦毁少年i
    2021-02-06 00:40

    -(void)getWebServic{
    NSURL *url = [NSURL URLWithString:@"----URL----"];
    
    // 2
    NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession]
                                          dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
    {
        NSDictionary *jsonObject=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        [self loadDataFromDictionary:(NSArray*)jsonObject];
        NSLog(@"data: %@",jsonObject);
    
    }];
    
    // 3
    [downloadTask resume]; }
    

提交回复
热议问题