IOS之路——暮色苍茫(Json)

来源:互联网 发布:手机淘宝如何让人代付 编辑:程序博客网 时间:2024/06/05 05:41

JSONKit
NSError* error;
NSURLRequest* request=[NSURLRequest requestWithRequest:[NSURL URLWithString:@"http://m.weather.com.cn/data/101010100.html"]];NSData* res=[NSURLConnection sendSynchromousRequest:request returningResponse:nil error: nil];NSDictionary *wertherDic=[res objectFromJSONData];NSDictionary *wertherInfo=[wertherDic objectForKey:@"weatherinfo"];txtView.text=[NSString stringWithFormat:@"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];  


ios5

 NSError *error;      //加载一个NSURL对象      NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.weather.com.cn/data/101180601.html"]];      //将请求的url数据放到NSData对象中      NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];      //IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中      NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];      NSDictionary *weatherInfo = [weatherDic objectForKey:@"weatherinfo"];      txtView.text = [NSString stringWithFormat:@"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];  


@property (retain, nonatomic) IBOutlet UITextView *txtView;  

@synthesize txtView;



额,我看一般都是有前言的,我也来点。

现在呢,我待业,然后呢,找工作,ios的,要求我去上机(这星期三),说是Json的解析,上网看到个很好的共勉之。

点击打开链接


点击打开链接




原创粉丝点击