objective c parse json from url request

前端 未结 7 1151
醉酒成梦
醉酒成梦 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条回答
  •  不知归路
    2021-02-06 00:30

    //call this method
    -(void)syncWebByGETMethod
    {
          [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
        NSString *urlString = [NSString stringWithFormat:@"http://www.yoursite.com"];
        NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
       [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]                          completionHandler:^(NSURLResponse * response, NSData * data, NSError * connectionError)
            {
             if (data)
             {
                 id myJSON;
                 @try {
                     myJSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                 }
                 @catch (NSException *exception) {
                 }
                 @finally {
                 }
                 jsonArray = (NSArray *)myJSON;
    
                 NSLog(@"mmm %@",jsonArray);
             }
         }];
    }
    

提交回复
热议问题