2013-02-12 90 views
-1

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

<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

此代码将帮助您。

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

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

NSArray *catArray = [dataDict allKeys]; 
+0

,我知道我想基于ITE型抓取menuCategory – 2013-02-12 11:50:22

+0

的NSArray * catArray = [dataDict allKeys];是你的解决方案 – junaidsidhu 2013-02-12 11:54:28

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"]); 
+0

你正在分配数组字典,它只会崩溃 – junaidsidhu 2013-02-12 11:57:06

+0

@ JayD- thans for infrom..check我编辑:0 – iPatel 2013-02-12 12:00:32

+0

这是我的相同答案 – junaidsidhu 2013-02-12 12:01:32