I want to use json in my application. I can parse json from url with this code :
#import \"ViewController.h\"
@implementation ViewController
{
NSDictiona
The way parsing should be same for Online
and Offline
json data, both are same, just you need to write a file using Unparsed
data say data.json
in Documents Directory
, if you want to use the same process to use json
, but if you want to use parsed json, then write it as plist
..
You can try to use the following methods
-(void)saveJsonWithData:(NSData *)data{
NSString *jsonPath=[[NSSearchPathForDirectoriesInDomains(NSUserDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingFormat:@"/data.json"];
[data writeToFile:jsonPath atomically:YES];
}
-(NSData *)getSavedJsonData{
NSString *jsonPath=[[NSSearchPathForDirectoriesInDomains(NSUserDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingFormat:@"/data.json"];
return [NSData dataWithContentsOfFile:jsonPath]
}
Then call the function as
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self saveJsonWithData:data];
}