0

我无法访问放置在此 plist 中的数组:

<?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>PageTitle</key>
        <string>Title</string>
        <key>Filters</key>
        <array>
            <dict>
                <key>Filter</key>
                <string>SomeFilter</string>
                <key>Param</key>
                <string>SomeParam</string>
            </dict>
            <dict>
                <key>Filter</key>
                <string>SomeFilter2</string>
                <key>Param</key>
                <string>SomeParam2</string>
            </dict>
        </array>
   </dict>
</array>
</plist>

我的代码如下(路径已正确设置):

NSMutableArray* propertyFile = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSMutableDictionary* dict = [propertyFile objectAtIndex:0];
NSMutableArray* filters = [dict[@"Filters"] mutableCopy];

'dict' 变量仅返回一个键/值对,即 'PageTitle' 键。“过滤器”键未被识别。对 iOS 来说非常新,似乎正在旋转我的轮胎试图解决这个问题。

4

1 回答 1

0

我刚刚运行了您的代码,并按预期获得了您的过滤器。你试过在 NSLog 中打印出你的过滤器吗?

2013-02-26 08:01:38.162 test[24849:c07] filters = (
        {
        Filter = SomeFilter;
        Param = SomeParam;
    },
        {
        Filter = SomeFilter2;
        Param = SomeParam2;
    }
)
于 2013-02-25T21:03:32.687 回答