Pratap Manish Bhadoria
Pratap Manish Bhadoria

Reputation: 371

how to pass arguments and parameters in json web service?

-(void)gettop10button
{   
    NSURL *url=[NSURL URLWithString:@"http://appabn.com/iphone/files/api/api.php?q=helo_users&u_id=5&page=1"];  // web api link

    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    connection=[NSURLConnection connectionWithRequest:request delegate:self];

in the last of the link we see that page=1 , i have more than 10 pages . so how can i pass a variable/parameter/argument , so i can increment page no. Thanks in advance 'int page; page++;

can perform like as .

in the last of the link we see that page=1 , i have more than 10 pages . so how can i pass a variable/parameter/argument , so i can increment page no. Thanks in advance 'int page; page++;

can perform like as .

if(connection)
{
    webData=[[NSMutableData alloc]init];
}   
[JustConfesstable reloadData];

Upvotes: 1

Views: 694

Answers (1)

Bhavin
Bhavin

Reputation: 27225

It's so simple. I am still amazed which part of the code you are not getting. You just have to take one variable (say pageNo) of type int and then provide it the default value 1. You just have to increment the pageNo (using pageNo++) to get the next page value and then you have to create string for URL with pageNo and then simply pass it to URL using the method called URLWithString of class NSURL.


Translation of all the above description in 4 easy steps using Objective-C :

NSString *urlString = [NSString stringWithFormat:@"http://appabn.com/iphone/files/api/api.php?q=helo_users&u_id=5&page=%d",pageNo];
NSURL *url = [NSURL URLWithString:urlString];  // web api link
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];

Upvotes: 1

Related Questions