读取plist时出错:stream的字节太少,格式为:-1073751400

时间:2011-10-23 17:30:38

标签: objective-c ios plist

我正在尝试从plist中读取一些数据并且我收到此错误:“读取plist时出错:stream的字节太少,格式为:-1073751400”

非常感谢任何帮助。

代码:

// read property list into memory as an NSData object
    NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
    NSString *errorDesc = nil;
    NSPropertyListFormat format;
    // convert static property liost into dictionary object
    NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
    if (!temp)
    {
        NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
    }
    // assign values
    self.excersizesArray = [NSMutableArray arrayWithArray:[temp objectForKey:@"Excersizes"]];

这是plist:

enter image description here

1 个答案:

答案 0 :(得分:1)

我可能会弄错,但是“Excersizes”数组是否必须包含在字典本身中?

那就是你必须在你的“Excersizes”数组周围放一个字典标签:

<dict>
 <key>Excersizes</key>
 <array>
 ...
 </array>
</dict>

至少你使用

  

self.excersizesArray = [NSMutableArray arrayWithArray:[temp objectForKey:@“Excersizes”]];

指向这个解决方案。这可能也会修复你的解析错误......