Reputation: 29
I'm calling a JSON
URL from the NSURL
class. My URL is:
like://Design_Time_Addresses/IServices/RoleService/json/Role/?name=%@",[textField text]];
When I write "doctor" in the textfield I have to get all the details of doctor through that URL. Similarly when I write "engineer" I have to get all the details of engineer. So it means what I type in the textfield, the name in URL should be replaced with the textfield value. But when I write the code like this:
NSURL *jsonUrl =[NSURL URLWithString:@"http://Design_Time_Addresses/ICloudServices/RoleService/json/Role/?name=%@",[textField text]];
NSString *jsonStr =[[NSString alloc] initWithContentsOfURL:jsonUrl];
NSMutableDictionary *jsonDetails = [[NSMutableDictionary alloc]initWithDictionary:[jsonStr JSONValue]];
As shown here I am using the NSURL
class to get this URL.
I am getting an error in the NSURL
class. How do I pass the text fields value to a URL?
Upvotes: 0
Views: 2712
Reputation: 15725
First line should be
NSString *urlString = [NSString stringWithFormat:@"http://Design_Time_Addresses/ICloudServices/RoleService/json/Role/?name=%@",[textField text]];
NSURL *jsonUrl =[NSURL URLWithString:urlString];
NSURL URLWithString
expects a single string argument, while you are providing two. Since you probably want to construct a single string from the @"http://..."
string and [textField text]
, you should use an NSString
method to concatenate them. You can't rely on NSURL
to concatenate the string for you.
Upvotes: 3