从IOS5开始,APPLE提供了对json的原生支持(NSJSONSerialization)
07 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@ "http://m.weather.com.cn/data/101010100.html" ]]; |
09 | NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; |
11 | NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; |
13 | NSDictionary *weatherInfo = [weatherDic objectForKey:@ "weatherinfo" ]; |
14 | Weather.text = [NSString stringWithFormat:@ "%@\n%@\n%@\n%@\n%@\n " , [weatherInfo objectForKey:@ "city" ],[weatherInfo objectForKey:@ "date_y" ],[weatherInfo objectForKey:@ "week" ], [weatherInfo objectForKey:@ "weather1" ], [weatherInfo objectForKey:@ "temp1" ]]; ; |
16 | NSLog(@ "weatherInfo字典里面的内容为--》%@" , weatherDic ); |
text显示的时候碰见内容一行显示解决方案
- 调整Label属性“Lines”为“6”
- 调整Label属性“Line breaks”为“Word Wrap”
参考: http://my.oschina.net/shootercn/blog/102084