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