Today want to write a request for the weather, good, nonsense not much to say, first paste code:
Send GET request using afnetworking, but always error IOS ' nsinternalinconsistencyexception ', Reason: ' Invalid parameter not satisfying: URLString '
The translation is not satisfied with the urlstring, possibly the request address is wrong, but the request address is correct, the return is a string of JSON data, and then I was confused, and then I found that the URL parameter is directly written up
, and then parameters put the parameters of the place did not put, and then I put the parameters in a separate written in, it was done Ah!
[Appdelegate.manager GET:@"http://api.map.baidu.com/telematics/v3/weather?location= Nanjing &output=json&ak=4zg5r7lw8fscvgnf2d3sqnqa "Parameters:nil success:^ (Afhttprequestoperation *operation,IDresponseobject) {Nsdictionary*rootdict=Responseobject; NSLog (@"%@", rootdict); Nsarray*resultarray = [Rootdict objectforkey:@"Results"]; Nsdictionary*citydict=[resultarray Objectatindex:0]; //get the cityNSString *currentcity= [citydict objectforkey:@"currentcity"]; //Getting ready for the weatherNsarray *weatherarray= [citydict objectforkey:@"Weather_data"]; //get a dictionary of the first day's weatherNsdictionary *firstdict=[weatherarray Objectatindex:0]; //get first Day dateNSString *firstdate=[firstdict Objectforkey:@"Date"]; //get the first day of weatherNSString *weather=[firstdict Objectforkey:@"Weather"]; //get the first day windNSString *wind=[firstdict Objectforkey:@" Wind"]; //get the first day of temperatureNSString *temper=[firstdict Objectforkey:@"Temperature"]; [[[Uialertview alloc] initwithtitle:[nsstring stringWithFormat:@"Current City%@\n Date:%@\n weather%@\n Wind%@\n temperature%@\n", Currentcity,firstdate,weather,wind,temper] Message:nilDelegate: Nil Cancelbuttontitle:@"Determine"Otherbuttontitles:nil, nil] show]; } Failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@"Link Failed"); }]; });
Correct code:
Nsdictionary *[email protected]{@" Location":@"Nanjing",@"Output":@"JSON",@"AK":@"4zg5r7lw8fscvgnf2d3sqnqa"}; [Appdelegate.manager GET:@"Http://api.map.baidu.com/telematics/v3/weather"Parameters:parameter success:^ (Afhttprequestoperation *operation,IDResponseobject) {
The parameters here must be written again parameters, or the links in those & symbols, as if not recognized!
IOS ' nsinternalinconsistencyexception ', Reason: ' Invalid parameter not satisfying:urlstring '