Today I want to write a request for the weather. Good. Don't say much nonsense. Paste the code First:
Send GET request using afnetworking, but always error IOS ' nsinternalinconsistencyexception ', Reason: ' Invalid parameter not satisfying: URLString '
Translation is not enough to meet urlstring. The request address is wrong when possible. But the request address is correct. The return is a string of JSON data. Then I got confused, and then I found out that the number of references in this URL was directly written.
, and then parameters the place to put the number of references. Then I wrote the number in separate. It's done.
[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 number of references here must be written in the parameters, otherwise the & symbols in the link. Doesn't seem to recognize it!
IOS & #39; nsinternalinconsistencyexception& #39;