ios - 从 XML Parse 匹配 NSDictionary

标签 ios objective-c xml

我有下面的代码,它是从 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"];

关于ios - 从 XML Parse 匹配 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26568511/

相关文章:

objective-c - 限制社交分享选项并为每项服务设置自定义消息

java - XSLT 1 : XPath - select/extract a number from a string, 带默认值

swift - 使用 SwiftyXMLParser Alamofire 解析 XML

javascript - 如何在React Native中完全关闭应用程序后保留应用程序的内存

ios - UICollectionView 单元格自动调整大小

ios - 3D 触摸到 UITabView

ios - imageview.hidden = false//选中 ^ true 表示未在 UITableView 中选中

ios - 可以跨线程安全地访问 bool var 吗?

ios - subview 的 CGRectIntersectsRect

android - NavigationDrawer,带有图像的适配器