gpt4 book ai didi

ios - 包含字典的数组的文件

转载 作者:行者123 更新时间:2023-11-29 11:04:54 25 4
gpt4 key购买 nike

我有一个包含字典数组的文件。我如何读回它以将其用作包含我的代码中的那些字典的常规数组?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>elem1</key>
<string>Hello world</string>
<key>elem2</key>
<string>This is some string</string>
</dict>
</array>
</plist>

最佳答案

这个其实很简单。感谢H2CO3指向它。只需使用 [NSArray arrayWithContentsOfFile:] 方法。所以这就是我得到的:

// Path to my file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"my_file.out"];

// Get the array contained in the file
NSMutableArray *myArray = [NSMutableArray arrayWithContentsOfFile:filePath];

// Read the array's content
int numOfelems = [myArray count];
for (int i = 0; i < numOfelems; i++) {
NSLog(@"Object at index %i: %@", i, [myArray objectAtIndex:i]);
}

关于ios - 包含字典的数组的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14115387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com