IOS development NOTE 3: XML/JSON data parsing, iosjson
This article mainly summarizes the methods used in XML/JSON data parsing in iOS development. XML data parsing mainly uses the NSXMLParser In the SAX mode and the GDataXML In the DOM mode, and the NSJSONSerialization in the json data parsing mode.
1. NSXMLParser for XML Parsing
NSXMLParser is a native XML Parsing Method for iOS. It uses the SAX Method for parsing. It is characterized by parsing each element from the root element in sequence.
Take the XML document as an example for parsing
(1) first, instantiate an NSXMLParser, set the proxy to listen to the parsing process, and start parsing.
Https://github.com/neonichu/GDataXML
Take the XML document used in the previous section as an example. You need to configure it before using it.
(1) set the header file path
If the outermost layer of the JSON string is neither NSArray nor NSDictionary, select NSJSONReadingAllowFragments for option.