我有下面的代码,它已经从XML解析中吐出来了,但是我不确定应该如何整合它。如何将所有“字符串”项添加到数组中?

解析器:

NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.url.net/directory/%@",fileName]]];
                NSDictionary *dict=[XMLParser dictionaryForXMLData:data error:nil];
                NSLog(@"%@",dict);


XMLParser是一个自定义类。

NSLog:

plist =     {
            dict =         {
                key =             (
                                    {
                        text = "\n\n\tmapFile";
                    },
                                    {
                        text = "\n\tmapPreviewFile";
                    },
                                    {
                        text = "\n\tmapScale";
                    },
                                    {
                        text = "\n\tmapper";
                    },
                                    {
                        text = "\n\tterrain";
                    },
                                    {
                        text = "\n\tTopLeft";
                    },
                                    {
                        text = "\n\tTopRight";
                    },
                                    {
                        text = "\n\tBottomLeft";
                    },
                                    {
                        text = "\n\tBottomRight";
                    }
                );
                string =             (
                                    {
                        text = "\n\thttp://www.url.com";
                    },
                                    {
                        text = "\n\thttp://www.url.com";
                    },
                                    {
                        text = "\n\t1 : 2 500";
                    },
                                    {
                        text = "\n\tSeb O'H (2014)";
                    },
                                    {
                        text = "\n\tUrban (school)";
                    },
                                    {
                        text = "\n\t42.87067222225,147.31143055";
                    },
                                    {
                        text = "\n\t42.8645138888888894, 147.3160527777777";
                    },
                                    {
                        text = "\n\t42.87067222222222, 147.3160527777777";
                    },
                                    {
                        text = "\n\t42.8645138888888894, 147.31143055555555";
                    }
                );
                text = "\n";
            };
            text = "\n";
            version = "1.0";
        };


我尝试了许多方法,但似乎仍然无法正常工作。简单来说,我的问题是,如何将NSDictionary中的一行放入NSArray中。
谢谢。

最佳答案

您可以简单地使用valueForKeyPath过滤数组

NSArray *text = [data valueForKeyPath:@"plist.dict.string.text"];

10-08 08:27