[Code Note] iOS-JSONKit usage, notes ios-jsonkit
1. Engineering Drawing.
Ii. Code.
# Import "RootViewController. h "// Add a header file for JSONKit # import" JSONKit. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. title = @ "use of JSONKit"; // use JSONKit to convert the dictionary into a string NSDictionary * jsonDic = [NSDictionary dictionaryWithObjectsAndKeys: @ "Li Xiaohua", @ "name ", @ "female", @ "sex", @ "23", @ "age", @ "BeiJing", @ "from", nil]; NSString * jsonString = [jsonDic JSONString]; NSLog (@ "------------- jsonDic -- % @", jsonDic); NSLog (@ "-------------- jsonString -- % @ -------", jsonString ); // convert the string into an array NSArray * jsonArr = [jsonString objectFromJSONString]; NSLog (@ "------ jsonArr ---- % @", jsonArr );}
3. output.
14:44:30. 160 use of JSONKit [12162: 246560] ------------- jsonDic -- {age = 23; from = BeiJing; name = "\ U674e \ U5c0f \ U534e"; sex = "\ U5973 ";} 14:44:30. 161 use of JSONKit [12162: 246560] -------------- jsonString -- {"age": "23", "sex": "female", "name": "Li Xiaohua ", "from": "BeiJing"} ------- 14:44:30. 162 use of JSONKit [12162: 246560] ------ jsonArr ---- {age = 23; from = BeiJing; name = "\ U674e \ U5c0f \ U534e"; sex = "\ U5973 ";}