【问题标题】:how to parse values plist file如何解析值plist文件
【发布时间】:2012-07-24 19:35:40
【问题描述】:

我是 iPhone 应用程序开发的新手。我现在正在开发 iPhone 应用程序。在这个应用程序中,我使用了 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, 
                   }
                )

             }
          )
       }   
  )

现在我需要单独解析这些值。

【问题讨论】:

    标签: iphone plist


    【解决方案1】:

    正在加载 plist,例如:

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

    然后你可以像使用 NSDictionary 一样使用 plist

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

    【讨论】:

      【解决方案2】:

      您的 .plist 文件不过是 NSDictionary 表示。将内容加载到字典中后,您就可以正常访问了。

      【讨论】:

        猜你喜欢
        • 2010-12-17
        • 2014-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多