-1

我有一个如下的 plist,在这个 plist 中,我想获取所有记录在一个值上的记录。在这里,我想根据 MenuType 的值获取所有 menuCategory 名称。如果用户选择 MenuTyp 为 veg,我想获取所有 menuCatogory,其中 Menutype 为 veg。这是plis结构请帮忙?

<dict>
            <key>MenuType</key>
            <string>NonVeg</string>
            <key>MenuCategory</key>
            <string>MainCourse</string>
            <key>MenuName</key>
            <string>KababHandi</string>
            <key>MenuPrice</key>
            <string>200</string>
            <key>MenuContents</key>
            <string>Kabab, Meat Masala, Salt</string>
        </dict>
4

2 回答 2

0
NSString *plistFilePath = [[NSBundle mainBundle]pathForResource:@"YourPlistFileName" ofType:@"plist"];
NSDictionary *yourDict = [[NSDictionary alloc]initWithContentsOfFile:plistFilePath];

    NSlog(@"%@",[yourDict objctForKey:@"MenuType"]);
    NSlog(@"%@",[yourDict objctForKey:@"MenuCategory"]);
    NSlog(@"%@",[yourDict objctForKey:@"MenuName"]);
    NSlog(@"%@",[yourDict objctForKey:@"MenuPrice"]);
    NSlog(@"%@",[yourDict objctForKey:@"MenuContents"]);
于 2013-02-12T11:51:41.243 回答
0

此代码将为您提供帮助。

NSString *fileName = [[NSBundle mainBundle]pathForResource:@"Data" ofType:@"plist"];

NSDictionary *dataDict = [[NSDictionary alloc]initWithContentsOfFile:fileName];

NSArray *catArray = [dataDict allKeys];
于 2013-02-12T11:48:10.277 回答