ios-xml和json的解析
#import "LYAppDelegate.h" #import <Foundation/Foundation.h> #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所以用的时候必须导入。
1.这里只记录一些学习笔记
2.这里只记录一些学习心得,如果心得方向有错,请留言
2.这里只记录一些日记(只为提升英语,暂时有点忙,等转行了开始写)