2012-07-24 60 views
0

我是新的iPhone應用程序開發。我正在開發iPhone應用程序。在這個應用程序中我使用plist(屬性列表)合成器給出了波紋管。如何解析值plist文件

Row 
    (item 0 
      { 
      title key string Africa 

      children 
      (
      item 0 
      { 
       title string Baobab 
       Children 
       (
        item 0 
        { 
        Image  string imagename, 
        Plant Name String plantname, 
        Description String discription, 
        Note   String Note, 
        } 
       ) 
      } 
      item 1 
      { 
       title string Baobab 
       Children 
       (
        item 0 
        { 
        Image  string imagename, 
        Plant Name String plantname, 
        Description String discription, 
        Note   String Note, 
        } 
       ) 

      } 
     ) 
     } 
     item 0 
      { 
      title key string America 

      children 
      (
      item 0 
      { 
       title string title_name1 
       Children 
       (
        item 0 
        { 
        Image  string imagename, 
        Plant Name String plantname, 
        Description String discription, 
        Note   String Note, 
        } 
       ) 
      } 
      item 1 
      { 
       title string title_name2 
       Children 
       (
        item 0 
        { 
        Image  string imagename, 
        Plant Name String plantname, 
        Description String discription, 
        Note   String Note, 
        } 
       ) 

      } 
     ) 
     } 
) 

現在我需要解析這個值分開。

回答

1

加載的Plist像:

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:@"your.plist"]; 

然後你就可以用的plist工作就像NSDictionary的

NSArray *keys = [dict allKeys]; 
for (NSString *key in keys) 
{ 
    NSMutableDictionary *item = [dict objectForKey:key]; 
    NSString *title = [item objectForKey:@"title"]; 
    ...... 
} 
0

你的.plist文件不過是一個NSDictionary表示。一旦內容加載到Dictionary中,您可以正常訪問它。