2015年1月24日 星期六

for test code

//
//  ijtJson.m
//  Injector
//
//  Created by Qbsuran Alang on 2014/10/23.
//  Copyright (c) 2014年 Qbsuran Alang. All rights reserved.
//

#import "ijtJson.h"

@implementation ijtJson
@synthesize dictionary;

- (id)initWithJsonString :(NSString *)json
{
    self = [super init];
    if(self && json)
    {
        NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        self->dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    
        if(error)
        {
            NSLog(@"ijtJosn initWithJsonString: %@", error.localizedDescription);
            return nil;
        }
    }
    return self;
}

- (id)initWithFilename :(NSString *)filename
{
    NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filename];
    NSData *data = [fileHandle readDataToEndOfFile];
    return [self initWithJsonString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
}

- (NSArray *)getKeys
{
    NSEnumerator * enumeratorKey = [self.dictionary keyEnumerator];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    //%u5FEB%u901F%u679A%u4E3E%u904D%u5386%u6240%u6709Value%u7684%u503C
    for (NSObject *object in enumeratorKey) {
        [array addObject:object];
    }
    return [NSArray arrayWithArray:array];
}

- (NSArray *)getValues
{
    NSEnumerator *enumeratorValue = [self.dictionary objectEnumerator];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    //%u5FEB%u901F%u679A%u4E3E%u904D%u5386%u6240%u6709Value%u7684%u503C
    for (NSObject *object in enumeratorValue) {
        [array addObject:object];
    }
    return [NSArray arrayWithArray:array];
}

- (NSDictionary *)getDictionary
{
    return self.dictionary;
}

- (NSUInteger)dataCount
{
    return  [self.dictionary count];
}

@end

沒有留言:

張貼留言