我有一个下面的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>
答案 0 :(得分:0)
此代码可以帮助您。
NSString *fileName = [[NSBundle mainBundle]pathForResource:@"Data" ofType:@"plist"];
NSDictionary *dataDict = [[NSDictionary alloc]initWithContentsOfFile:fileName];
NSArray *catArray = [dataDict allKeys];
答案 1 :(得分: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"]);