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

发布于 2024-12-11 17:57:26 字数 901 浏览 0 评论 0原文

我正在尝试从 plist 中读取一些数据,但收到此错误:“读取 plist 时出错:流字节太少,格式:-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:

在此处输入图像描述

I'm trying to read some data out of a plist and I'm getting this error: "Error reading plist: stream had too few bytes, format: -1073751400"

Any help would be much appreciated.

code:

// 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"]];

Here's the plist:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见终念 2024-12-18 17:57:26

我可能错了,但是“Excersizes”数组不是必须包含在字典本身中吗?

也就是说,您必须在“Excersizes”数组周围放置一个字典标签,如下所示:

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

至少您使用

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

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

I might be mistaken, but doesn't the "Excersizes" array has to be wrapped within an dictionary itself?

That is you have to put a dictionary tag around your "Excersizes" array like this:

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

At least your use of

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

points towards this solution. This might fix your parsing error as well...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文