To integrate JSON framework in IOS applications use following steps.
- Have a look at the features Introductions at google’s home page
- Download and extract the source from GitHub
- Rename directory named Classes to JSON.
-
This step will involve some small individual steps
- Move the renamed directory to Classes directory of target project
- Open target project choose Classes group
- Now right click and choose Add -> Existing files and add JSON to it.
-
Usage
- Import json.h in the class you wish to use json.
- For ObjC to JSON you can call JSONRepresentaion on any object
NSArray *arr=[NSArray arrayWithObjects:@"1",@"2",@"3",nil]; NSLog(@"%@",[arr JSONRepresentation]);
logs [“1″,”2″,”3”]; -
For JSON to ObjC you need to parse the string to convert JSON to an ObjC object.
SBJsonParser *parser=[[SBJsonParser alloc] init]; NSArray *arr2=[parser objectWithString:@"[\"1\",\"2\",\"3\"]"]; NSLog(@"%@",arr2);
And that’s it,you are done with JSON Integration.