NSString にある json データを解析したいのですが、どうすればよいですか
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);
NSArray *tempArray =[[DataController staticVersion] startParsing:data];
for (int i = 0; i<[tempArray count]; i++) {
id *item = [tempArray objectAtIndex:i];
NSDictionary *dict = (NSDictionary *) item;
SearchCode *theObject =[[SearchCode alloc] init];
[theObject setCodeValue:[dict objectForKey:@"CodeValue"]];
[theObject setCodeDescription:[dict objectForKey:@"CodeAddedDate"]];
[theObject setCodeAddedDate:[dict objectForKey:@"CodeAddedDate"]];
[theObject setCodeID:[dict objectForKey:@"CodeID"]];
[theObject setUpdateDateTime:[dict objectForKey:@"UpdateDateTime"]];
[cptArray addObject:theObject];
[theObject release];
theObject=nil;
}
DataController クラス
@interface DataController : NSObject {
}
+ (id)staticVersion;
- (NSMutableArray *) startParsing:(NSString *)theURLString;
@end
#import "DataController.h"
#import "JSON.h"
@implementation DataController
DataController *theInstance;
+(id)staticVersion
{
if(!theInstance){
theInstance = [[DataController alloc] init];
}
return theInstance;
}
- (NSMutableArray *) startParsing:(NSString *)theURLString {
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",theURLString]];
NSString *fileContent= [NSString stringWithContentsOfURL:url];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:fileContent error:nil];
NSArray *items = (NSArray *) data ;
return items;
}
@end