任何人都可以帮助正确加载字典对象到数组中。 将plist加载到字典对象中工作正常,我能够将其中的一部分输出到命令行中。 问题是,这种加载方式将每个名称和价格集合放入数组中的同一个单元格中。 IE: 是否可以单独加载它们?或者,也许在某种二维数组中有一个单元格用于名称和其他价格。解析词典从plist到数组
在此先感谢。
测试是一个可变数组。
NSString* path = [[NSBundle mainBundle] pathForResource:@"property" ofType:@"plist"];
NSDictionary* amountData = [NSDictionary dictionaryWithContentsOfFile:path];
if (amountData) {
Test = [NSMutableArray arrayWithArray: amountData];
}
而我的plist结构为:
<dict>
<key>New item</key>
<dict>
<key>Name</key>
<string>Property 1</string>
<key>Price</key>
<string>100000</string>
</dict>
<key>New item - 2</key>
<dict>
<key>Name</key>
<string>Property 2</string>
<key>Price</key>
<string>300000</string>
</dict>
<key>New item - 3</key>
<dict>
<key>Name</key>
<string>Property 3</string>
<key>Price</key>
<string>500000</string>
</dict>
<key>New item - 4</key>
<dict>
<key>Name</key>
<string>Property 4</string>
<key>Price</key>
<string>600000</string>
</dict>
</dict>
问题的阵列的方法是,它返回每个行为: 行0:{ 名称= “属性1”; Price = 100000; } 我想知道如果更容易的方式加载这个,而不必手动解析括号等。 或者如果我可以直接从字典访问值拉出让我们说名称。 – totallhellfail 2010-08-25 15:56:33
我不确定我完全理解你的问题。你会得到的是你想要的阵列。获取所有名称可以使用像这样的想法来完成:'[Test valueForKeyPath:@“name”]' - 返回一个包含所有名称的数组。 – 2010-08-25 18:26:24
这听起来像我在找的东西; D谢谢。 – totallhellfail 2010-08-25 23:03:22