diff --git a/EGOCache.h b/EGOCache.h index 05158cf..f4b7ddb 100755 --- a/EGOCache.h +++ b/EGOCache.h @@ -70,6 +70,11 @@ - (void)setPlist:(id)plistObject forKey:(NSString*)key; - (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; +- (id)jsonObjectForKey:(NSString*)key; +- (id)mutableJsonObjectForKey:(NSString*)key; +- (void)setJson:(id)jsonObject forKey:(NSString*)key; +- (void)setJson:(id)jsonObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; + - (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key; - (void)copyFilePath:(NSString*)filePath asKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval; diff --git a/EGOCache.m b/EGOCache.m index 556c9ce..6f872a1 100755 --- a/EGOCache.m +++ b/EGOCache.m @@ -357,6 +357,33 @@ - (void)setPlist:(id)plistObject forKey:(NSString*)key withTimeoutInterval:(NSTi [self setData:plistData forKey:key withTimeoutInterval:timeoutInterval]; } +#pragma mark - +#pragma mark JSON Object methods + +- (id)jsonObjectForKey:(NSString*)key { + NSData* jsonData = [self dataForKey:key]; + + return [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil]; + +} + +- (id)mutableJsonObjectForKey:(NSString*)key { + NSData* jsonData = [self dataForKey:key]; + + return [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; + +} + +- (void)setJson:(id)jsonObject forKey:(NSString*)key { + [self setJson:jsonObject forKey:key withTimeoutInterval:self.defaultTimeoutInterval]; +} + +- (void)setJson:(id)jsonObject forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval { + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:nil]; + + [self setData:jsonData forKey:key withTimeoutInterval:timeoutInterval]; +} + #pragma mark - #pragma mark Object methods