2 Jan 2017

JSON GET DATA


 JSON GetData...

@property NSMutableURLRequest *urlRequestFree;
@property NSURLSessionConfiguration *urlSessionConfigurationFree;
@property NSURLSession *urlSessionFree;
@property NSURLSessionDataTask *dataTaskFree;
@property NSMutableDictionary *freeAppsData;


-(void) JsonPost  {

self.urlRequestFree=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"https://itunes.apple.com/in/rss/topfreeapplications/limit=200/json"]];
    self.urlSessionConfigurationFree=[NSURLSessionConfiguration defaultSessionConfiguration];
    self.urlSessionFree=[NSURLSession sessionWithConfiguration:self.urlSessionConfigurationFree];
    
    self.dataTaskFree=[self.urlSessionFree dataTaskWithRequest:self.urlRequestFree completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        self.freeAppsData=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSLog(@"%@",self.freeAppsData);
    }];
    [self.dataTaskFree resume];

    
}

2 comments:


  1. NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat: @"https://itunes.apple.com/us/rss/topaudiobooks/limit=10/json"]]] options:kNilOptions error:&error];

    for (int i=0; i<9; i++) {

    NSLog(@"json: %@", [[[[[json objectForKey:@"feed" ]objectForKey:@"entry"]objectAtIndex:i]objectForKey:@"title"]objectForKey:@"label"]);

    }

    ReplyDelete
  2. self.mutableArr =[[NSMutableArray alloc]init];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"https://itunes.apple.com/in/rss/topfreeebooks/limit=10/json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject)
    {
    NSLog(@"JSON: %@", responseObject);
    for (int i=0; i<9; i++)
    {
    [self.mutableArr addObject:[[[[[responseObject objectForKey:@"feed" ]objectForKey:@"entry"]objectAtIndex:i]objectForKey:@"im:name"]objectForKey:@"label"]];

    }
    } failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error: %@", error);
    }

    ];

    ReplyDelete

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0