我像这样保存一个 NSDictionary:
NSDictionary *menuList = [[NSDictionary alloc]initWithDictionary:xmlParser.items];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithUTF8String:MENU_LIST_NAME];
NSString *filePath = [directory stringByAppendingPathComponent: fileName];
[menuList writeToFile:filePath atomically:YES]
正如所见,字典充满了数据,应该是这样。
我从这样的文件中读取:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithUTF8String:MENU_LIST_NAME];
NSString *filePath = [directory stringByAppendingPathComponent:fileName];
NSDictionary *theMenu = [[NSDictionary alloc] initWithContentsOfFile:filePath];
但是在这里我只得到空对象:
我只是找不到解决方案。请帮忙。谢谢你。编辑:文件内容(似乎写得正确)
<dict>
<key>left</key>
<array>
<dict>
<key>id</key>
<string>1</string>
<key>level</key>
<string>1</string>
<key>link</key>
<string>
LoginActivity</string>
<key>linkType</key>
<string>internal</string>
<key>state</key>
<string>ANY</string>
<key>title</key>
<string>
Login</string>
<key>visible</key>
<true/>
</dict>
etc....