#import "LYAppDelegate.h"#import#import "XMLReader.h"#import "JSONKit.h"@implementation LYAppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; // NSURL *url=[NSURL URLWithString:@"http://www.w3school.com.cn/example/xmle/note.xml"];//xml NSURL *urljson=[NSURL URLWithString:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=39.904299,116.22169&sensor=true"];//json NSMutableURLRequest* request= [[NSMutableURLRequest alloc]initWithURL:urljson cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60]; NSOperationQueue*queue= [[NSOperationQueue alloc]init];// [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {// NSError * error=nil;// NSDictionary *dic=[XMLReader dictionaryForXMLData:data error:&error];// NSLog(@"%@",[[[dic objectForKey:@"note"] objectForKey:@"from"] objectForKey:@"text"]);// // }]; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSDictionary * dic=[data objectFromJSONData]; NSLog(@"dic%@",[[dic objectForKey:@"results"][5]objectForKey:@"formatted_address"]); }];//json解析 return YES;}@end
xml的解析我们用XMLReader,json的解析我们用JSONKit,这2库已经同步到百度云了,用的时候去拿,同时JSONkit依赖foundatin框架的libz.dylib所以用的时候必须导入。