One, code.
Get the weather forecast for Xujiahui-(void) getweatherinfo{ nserror *error; Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:@ "http://m.weather.com.cn/data/101021200. HTML "]];//code for Xujiahui nsdata *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error: NIL]; Nsdictionary *weatherdic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves error:&error]; Nsdictionary *weatherinfo = [weatherdic objectforkey:@ "Weatherinfo"]; NSLog (@ "Weather%@", [NSString stringwithformat:@ "\n%@\n%@\n%@\n%@\n%@\n", [Weatherinfo objectforkey:@ "City"],[ Weatherinfo objectforkey:@ "date_y"],[weatherinfo objectforkey:@ "Week"], [Weatherinfo objectforkey:@ "Weather1"], [ Weatherinfo objectforkey:@ "Temp1"]); }
Two, output.
Weather Xujiahui March 4, 2014 Tuesday Rain Turn cloudy 11℃~6℃
"Code Notes" get Weather forecast for Xujiahui