Как получить данные json с сервера эффективным и быстрым способом?
Hey folks, I've the following code to get data from server but it takes too long to load and show in tableView. I need it to be done in faster way. I have my NSURLRequest in viewDidLoad.
- (void)viewDidLoad { NSNumber *getID=connectorClass.IdBeingPassed; NSString *getname=connectorClass.movieNameBeingPassed; NSNumber *getVote=connectorClass.voteBeingPassed; NSString *myNumberInString = [getVote stringValue]; NSString *movieIDinString= [getID stringValue]; _labelText.text=getname; //------castApi----// [super viewDidLoad]; [[self tableView2]setDelegate:self ]; [[self tableView2]setDataSource:self]; array=[[NSMutableArray alloc]init]; NSString *castString = [NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@/credits?api_key=c4bd81709e87b1208609433c49",movieIDinString]; NSURL *url=[NSURL URLWithString:castString]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; connection=[NSURLConnection connectionWithRequest:request delegate:self]; if (connection) { webData= [[NSMutableData alloc]init]; } }
Что я уже пробовал:
- (void)viewDidLoad { NSNumber *getID=connectorClass.IdBeingPassed; NSString *getname=connectorClass.movieNameBeingPassed; NSNumber *getVote=connectorClass.voteBeingPassed; NSString *myNumberInString = [getVote stringValue]; NSString *movieIDinString= [getID stringValue]; _labelText.text=getname; //------castApi----// [super viewDidLoad]; [[self tableView2]setDelegate:self ]; [[self tableView2]setDataSource:self]; array=[[NSMutableArray alloc]init]; NSString *castString = [NSString stringWithFormat:@"https://api.themoviedb.org/3/movie/%@/credits?api_key=c4bd81709e87b1208609433c49",movieIDinString]; NSURL *url=[NSURL URLWithString:castString]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; connection=[NSURLConnection connectionWithRequest:request delegate:self]; if (connection) { webData= [[NSMutableData alloc]init]; } }
Mehdi Gholam
Ваша проблема может быть не в" получении " части, а в просмотре части, профиль вы кодируете, чтобы увидеть, какая часть медленная в первую очередь.