2013-02-12 92 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