This article summarizes the methods used in the Xml/json data parsing process in iOS development. The parsing of XML data mainly uses the Nsxmlparser of sax and the Gdataxml,json data parsing of Dom method mainly use Nsjsonserialization.
1.XML Analysis of Nsxmlparser
Nsxmlparser is the native XML parsing method of iOS, parsing by sax, characterized by the time of parsing from the root element, in order to parse each element sequentially.
Parsing as an example of the XML document shown
(1) The first is to instantiate a nsxmlparser, set up the agent listening parsing process, start parsing
(2) Parsing XML documents by Nsxmlparser Proxy method
(3) Analytic effect
2.XML Analysis of Gdataxml
Gdataxml is a class library of parsing XML data produced by Google, based on LIBXML2, which is characterized by Dom parsing, which loads XML document data into memory once and then parses the data.
:Https://github.com/neonichu/GDataXML
or use the XML document from the previous section as an example, you need to configure it before use
(1) Set header file path
(2) Setting link parameters
(3) Set compilation parameters (Gdataxml is non-arc)
Load the entire XML document and iterate through the elements to
Nsjsonserialization of 3.JSON data analysis
JSON data format has the following requirements, so the data after the corresponding resolution can be used in the development of JSON as a foundation object
Get JSON data directly using Nsjsonserialization parsing
When the outermost layer of a JSON string is neither Nsarray nor nsdictionary, option chooses nsjsonreadingallowfragments
iOS Development note 3:xml/json Data parsing