• 【代码笔记】iOS-获得徐家汇的天气预报


    一,代码。

    复制代码
    //获得徐家汇的天气预报
    -(void)getWeatherInfo{
        
        NSError *error;
        
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.weather.com.cn/data/101021200.html" ]];//代码为徐家汇
        
        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        
        NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response  options:NSJSONReadingMutableLeaves error:&error];
        
        NSDictionary *weatherInfo = [weatherDic objectForKey:@"weatherinfo"];
        
        NSLog(@"天气%@",[NSString stringWithFormat:@"
    %@
    %@
    %@
    %@
    %@
     ", [weatherInfo objectForKey:@"city"],[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]]);
        
    }
    复制代码

     

    二,输出。

    天气
         徐家汇
         2014年3月4日
         星期二
         小雨转多云
         11℃~6℃

     

     

     
     
  • 相关阅读:
    赔了多少钱
    datatables使用
    Django开发汇总
    STF的DOCKER搭建
    ubuntu基本
    python 列表、元组、字典、字符串
    Appium环境搭建
    AppCrawler环境搭建
    TASK 总结
    python & jira
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5645757.html
Copyright © 2020-2023  润新知