2016-06-14 48 views
0

我在整个互联网上搜索如何将我的XML数据存储到NSDictionary,但似乎我找不到解决方案,将解决我的问题。我需要将我的数据存储到NSDictionary中,数据来自存储在url中的xml。有没有关于如何做的算法?不使用任何第三方程序,如果可能的如何将URL从URL存储到NSDictionary?

+0

[解析XML到NSDictionary]可能的重复(http://stackoverflow.com/questions/26553557/parse-xml-to-nsdictionary) –

回答

0

使用NSXMLParser

NSURL *yoururl = [NSURL URLWithString:[NSString stringWithFormat:@"http://Enter your URL here"]]; 
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:yoururl]; 
parser.delegate = self; 
[parser parse]; 

-(void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI 
qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict 
{ 
    //Use attributeDict to get parsed XML into NSDictionary 
} 

如需更多信息请参阅本:

Xml parsing in iOS tutorial

我希望这将帮助你.. :)

+0

它是否正常l在我的xml文本中有\ t和\ n?我可以解析它,这里是一个示例文本=“\ n \ t \ t \ n \ t \ t \ tCheck”; – drbj

+0

看到这个兄弟:https://www.raywenderlich.com/553/xml-tutorial-for-ios-how-to-choose-the-best-xml-parser-for-your-iphone-project OR .. https ://github.com/71squared/TBXML –