Blog http://blog.csdn.net/duxinfeng2010/article/details/7842210
TouchJson library parsing
- (IBAction) buttonPressedone: (id) sender {
/ / Get API interface
NSURL * url = [NSURL URLWithString: @ "http://m.weather.com.cn/data/101010100.html"];
/ / Define a NSError object to capture error messages
NSError * error;
/ /
NSString * jsonString = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: & error];
/ / NSLog (@ "jsonstring --->% @", jsonString);
/ / Get the contents of the store will be resolved in the dictionary, the encoding format UTF8, to prevent distortion occurs when the value
NSDictionary * rootDic = [[CJSONDeserializer deserializer] deserialize: [jsonString dataUsingEncoding: NSUTF8StringEncoding] error: & error];
/ / Because there are two return Json file, go to the second floor into the dictionary class content to 0?
NSDictionary * weatherInfo = [rootDic objectForKey: @ "weatherinfo"];
/ / Value Print
NSLog (@ "Today is% @% @% @ weather conditions are:% @% @", [weatherInfo objectForKey: @ "date_y"], [weatherInfo objectForKey: @ "week"], [weatherInfo objectForKey: @ "city "], [weatherInfo objectForKey: @" weather1 "], [weatherInfo objectForKey: @" temp1 "]);
}
SBJson library parsing
- (IBAction) buttonPressedtwo: (id) sender {
NSURL * url = [NSURL URLWithString: @ "http://m.weather.com.cn/data/101180701.html"];
NSError * error = nil;
NSString * jsonString = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: & error];
SBJsonParser * parser = [[SBJsonParser alloc] init];
NSDictionary * rootDic = [parser objectWithString: jsonString error: & error];
NSDictionary * weatherInfo = [rootDic objectForKey: @ "weatherinfo"];
NSLog (@ "Today is% @% @% @ weather conditions are:% @% @", [weatherInfo objectForKey: @ "date_y"], [weatherInfo objectForKey: @ "week"], [weatherInfo objectForKey: @ "city "], [weatherInfo objectForKey: @" weather1 "], [weatherInfo objectForKey: @" temp1 "]);
}
iOS5 comes parse class of analytic
- (IBAction) buttonPressedthree: (id) sender {
NSError * error;
/ / Load a NSURL object
NSURLRequest * request = [NSURLRequest requestWithURL: [NSURL URLWithString: @ "http://m.weather.com.cn/data/101180601.html"]];
/ / The url requested data into NSData object
NSData * response = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
/ / IOS5 comes parsing class NSJSONSerialization parse out the data from the response into the dictionary
NSDictionary * weatherDic = [NSJSONSerialization JSONObjectWithData: response options: NSJSONReadingMutableLeaves error: & error];
/ / WeatherDic dictionary data is also stored in a typical word from inside it through the key value
NSDictionary * weatherInfo = [weatherDic objectForKey: @ "weatherinfo"];
NSLog (@ "Today is% @% @% @ weather conditions are:% @% @", [weatherInfo objectForKey: @ "date_y"], [weatherInfo objectForKey: @ "week"], [weatherInfo objectForKey: @ "city "], [weatherInfo objectForKey: @" weather1 "], [weatherInfo objectForKey: @" temp1 "]);
/ / Print out the stored data
weatherInfo dictionaryNSLog (@ "weatherInfo dictionary content inside is --->% @", [weatherInfo description]);
}
Reply:
Well, first on the favorites, but even the best point format LZ perfect
ios developed super group, between masters and masters to those indicated from CSDN: 43146334
No comments:
Post a Comment