When using third-party sdks, you can often compile your classes into static libraries. you can hide your private information, such as private APIs and apikey, when provided to developers;
Compile the open-source jsonkit class library into a static library, and then use the compiled static library to parse a JSON file.
1. Create a static library project, select framework & library -- next, and name it jsonkitlib.
2. Delete automatically generated jsonkitlib. h and jsonkitlib. H (because they are packed with other people's classes, you do not need to delete these two files if you create them yourself;
3. note that the IOS simulator is based on the X86 architecture of the Mac OS platform and the ARM architecture is applied to iOS devices. Therefore, the static library provided to them must also be applied to their architecture, fortunately, xcode can compile the libraries of these two architectures at the same time;
During compilation, it is adjusted to iOS device, product --> build. If it is adjusted to others, it cannot compile static libraries.
4. after compilation is successful, libjsonkitlib will be released. a. Right-click and select Show in finder. There will be a static library under the debug-iphoneos and debug-iphonesimulator folders. Let's take a look at the file type with lipo.
One is the ARM architecture and the other is the i386 architecture of the X86 platform. If we want to run the test on the simulator, We need to copy the static library under debug-iphonesimulator, if you need to test a real machine or a real machine, it must be a static library under debug-iphoneos;
5. now we can test the compiled static library. It is best to copy both libraries for easy addition and use. Create an xcode project and run jsonkit. add the H file to the new project, and then add the static library compiled under debug-iphonesimulator.
6. The test code here uses the National Meteorological Administration API and the JSON file is returned.
-(Ibaction) tapjsonpaser :( ID) sender {nserror * error; nsurlrequest * request = [nsurlrequest requestwithurl: [nsurl urlwithstring: @ "http://m.weather.com.cn/data/101180701.html"]; nsdata * repsponse = [nsurlconnection failed: request failed: Nil error: & error]; jsondecoder * jsonpaser = [[jsondecoder alloc] init]; nsdictionary * weatherdic = [jsonpaser objectwithdata: repsponse error: & error]; nslog (@ "Resolution result: % @", weatherdic); [jsonpaser release];}
Result
However, some people may think it is too troublesome to pack these two static libraries into a static library and use commands.
Lipo-create debug-iphoneos/libjsonkitlib. A debug-iphonesimulator/libjsonkitlib. A-output libjsonkittestlib.
Although the method is good, it will sacrifice space and the file will become larger. The jsonkit source file is 12kb + 177kb, and after being compiled into a static library, the ARM architecture's ipvkb i386 architecture is 263kb, package them into a static database of kb;