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= 4zg5r7sqnqa "Parameters:nil success:^ (afhttprequestoperation *operation, id responseobject) {NSDictionary *roo Tdict=responseobject; NSLog (@ "%@", rootdict); Nsarray *resultarray = [rootdict objectforkey:@ "Results"]; Nsdictionary *citydict=[resultarray objectatindex:0]; Get the city nsstring *currentcity= [citydict objectforkey:@ "currentcity"]; Prepare to get the weather nsarray *weatherarray= [citydict objectforkey:@ "Weather_data"]; Get the first day of the weather dictionary nsdictionary *firstdict=[weatherarray objectatindex:0]; Get the first day date nsstring *firstdate=[firstdict objectforkey:@ "Date"]; Get the first day weather nsstring *weather=[firstdict objectforkey:@ "Weather"]; Get the first day wind nsstring *wind=[firstdict objectforkey:@ "winds"]; Get the first day of temperature Nsstring *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:nil delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil] show]; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "link failed"); }]; });
Correct code:
Nsdictionary *[email protected]{@ "location": @ "Nanjing", @ "output": @ "JSON" @ "AK": @ "4zg5r7lw8fd3sqnqa"}; [Appdelegate.manager get:@ "Http://api.map.baidu.com/telematics/v3/weather" Parameters:parameter success:^ ( Afhttprequestoperation *operation, id responseobject) {
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 '