txt ファイルを NSDictionary に解析するにはどうすればよいですか?
私のファイルは次のようになります
JACK - (mr) - address
99000 - City
Phone : 09 93 81 48 51
Website
これは私のコードです:
NSString *file = [[NSBundle mainBundle]pathForResource:@"MyFile" ofType:@"txt"];
NSError *error;
NSString *text = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:&error];
NSArray * testArray = [[NSArray alloc] init];
testArray = [text componentsSeparatedByString:@" \n"];
以降
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for (NSString *s in testArray)
{
NSArray *arr = [s componentsSeparatedByString:@" -"];
[dict setObject:[arr objectAtIndex:0] forKey:@"name"];
NSLog(@"Dictionary: %@", [dict description]);
}
そして私の NSLog は私に与えます:
Dictionary: {
name = "JACK";
}
ファイルの残りを解析して「mr」とアドレスの後に取得する方法....?