iOS Development note 3:xml/json Data parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.