不能从plist读取数据 [英] Cant read data from plist

查看:92
本文介绍了不能从plist读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从plist文件中读取数据时遇到问题。提取字符串中值的正确方法是什么?并且假设我有2个项目,我如何获得两个项目?下面是plist上的图像。

I am having trouble with reading data from my plist file. What is the correct way of extracting the values in a string? And lets say I have 2 items, how do I get both? Below will be the image on the plist.

以下是源代码对于plist。我在某处看到Xcode 3和Xcode 4可能存在差异。

And below is the source code for the plist. I read somewhere that there could be a difference with Xcode 3 and Xcode 4.

<?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">
<dict>
    <key>Array</key>
    <array>
        <string>value 1</string>
        <string>value 2</string>
    </array>
</dict>
</plist>


推荐答案

请回复此问题。但我设法找到了一个让它适合我的代码。代码如下。感谢peylow为您的努力。

do reply about this still. But I managed to find a code that got it working for me already. The codes are below. Thanks peylow for your effort.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"EventAddress" ofType:@"plist"]; 
    NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

    NSArray* allmyKeys = [myDictionary  allValues];
    NSLog(@"%@", allmyKeys);
    NSLog(@"%@", [[allmyKeys objectAtIndex:0] objectAtIndex:0]);

最后2个NSLog用于查看我的plist是否返回值数组并查找其中只有1个的价值。非常感谢调试器,在看了好几天后,我也意识到了我的问题。该死的阵列不是正常的一维,它的二维。这就是为什么我两次使用objectAtIndex。

The last 2 NSLog is used to see if my plist does return an array of values and to find out the value of only 1 of them. And thanks a lot about the debugger, after looking at it for almost 3 days straight, I also realized my problem. The damn array isn't the normal one dimension, its TWO DIMENSION. Thats why I used objectAtIndex twice.

这篇关于不能从plist读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆