NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey]; NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey]; 还有其它很多信息可由infoDictionary获得,以下是官方文档里的说明: information Property List Keys Standard keys found in a bundle’s information property list file. const CFStringRef kCFBundleInfoDictionaryVersionKey; const CFStringRef kCFBundleExecutableKey; const CFStringRef kCFBundleIdentifierKey; const CFStringRef kCFBundleVersionKey; const CFStringRef kCFBundleDevelopmentRegionKey; const CFStringRef kCFBundleNameKey; const CFStringRef kCFBundleLocalizationsKey; Constants kCFBundleInfoDictionaryVersionKey The version of the information property list format. Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleExecutableKey The name of the executable in this bundle (if any). Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleIdentifierKey The bundle identifier. Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleVersionKey The version number of the bundle. For Mac OS 9 style version numbers (for example “2.5.3d5”), clients can use CFBundleGetVersionNumber instead of accessing this key directly since that function will properly convert the version string into its compact integer representation. Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleDevelopmentRegionKey The name of the development language of the bundle. When CFBundle looks for resources, the fallback is to look in the lproj whose name is given by the kCFBundleDevelopmentRegionKey in the Info.plist file. You must, therefore, ensure that a bundle contains an lproj with that exact name containing a copy of every localized resource, otherwise CFBundle cannot guarantee the fallback mechanism will work. Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleNameKey The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized. Available in iOS 2.0 and later. Declared in CFBundle.h. kCFBundleLocalizationsKey Allows an unbundled application that handles localization itself to specify which localizations it has available. Available in iOS 2.0 and later. Declared in CFBundle.h. Declared In CFBundle.h
使用jsonKit
归档.zip中包含JsonKit开源文件
//jsonKit不支持ARC,如果项目使用了ARC也不要紧
//配置一下就可以正常使用了
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/lookup?id=284910350"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; // NSData *jsonData = [] [self.window makeKeyAndVisible]; return YES; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSString *outString = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding]; NSData *jsonData = [outString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *dic = [jsonData objectFromJSONData]; NSArray *dic1 = [dic objectForKey:@"results"]; NSDictionary *dic2 = [dic1 objectAtIndex:0]; NSLog(@"%@", [dic2 objectForKey:@"version"]); }