//
//  NSString+Extension.m
//  ChaoJuEyes
//
//  Created by hzyd on 13-7-10.
//  Copyright (c) 2013年 hzyd. All rights reserved.
//

#import "NSString+Extension.h"
@implementation NSString (Extension)

-(id)jsonValue{
    NSError* err;
    id value = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&err];
    if (err) {
        NSLog(@"error when json %@",err.description);
        return nil;
    }
    return value;
}

-(NSString *)appendForPath
{
    
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:self];
    
    return path;
}
+(NSString *)getFilePathWithDir:(NSString *)aDirectory file:(NSString *)aFilename
{
    NSString *dirpath = [aDirectory appendForPath];
    
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:dirpath]) {
        [manager createDirectoryAtPath:dirpath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
    return [dirpath stringByAppendingPathComponent:aFilename];
    
}
//判断是否是有效的手机号
-(BOOL)isEmptyOrNil
{
//    return !self|| ![self length] || [self isEqualToString:@"null"] || [self isEqualToString:@""]  ||  [self isEqualToString:@"\"null\""];
    return !self.length;
}

-(NSString*) urlEncodedString
{
    NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)self ,NULL ,CFSTR("!*'();:@&=+$,/?%#[]") ,kCFStringEncodingUTF8));
    return result;
}
@end
