Parsing Xml/json in iOS

Source: Internet
Author: User

JSON data format

1. Overview:
JSON (JavaScript Object Notation) is a lightweight data interchange format

Based on the text format, easy to read and write, but also easy to machine analysis and build.

2. The format of the JSON data is: name/value • The name is written in the front face (in double quotes)
• Value pairs are written on the back face
• Middle? Separated by a colon

3. JSON value? Type of support

    • Number (integer or floating point)

    • String (in double quotes)

    • Logical value (TRUE or FALSE)

    • Array (in brackets)

    • Object (in curly braces)

    • Null

JSON format? One: The outermost is? curly braces

Online JSON format? Tool http://json.phpddt.com

Url:

Http://api.openweathermap.org/data/2.5/weather?q=beijing&units=metric

JSON format? Two: The outermost is the middle bracket

1. JSON value? The correspondence between the supported types and OC objects

    • Digital-NSNumber

    • Double quote-NSString

    • Nsarray, Brackets

    • ? curly Braces--nsdictionary

    • Null-> NSNull

      2. Object to model: Convert the parsed OC object (nsarray/nsdictionary) to a custom model class

XML data format

1. XML (extensible Markup Language) Extensible Markup Word,
• Is it a type of marker that is used to mark the electrical sub-document so that it has a structured markup language?
XML is a common language used in the transfer of data between various applications.

2. Three terms for XML documents:

    • root element: Outermost element

    • Element: From the start tag until the end of the label's section

    • Attribute (Attribute): Provides additional information about the element

1. XML sample?:

2. XML sample? Two:

1. XML parsing? Mode:

    • DOM:? Load the entire XML document into memory at once, through the element structure within the XML document, parse out the element pair

      Expected value/attribute

    • SAX: Starting with the root element of the XML document, parsing the elements sequentially

      2. Parsing XML in iOS? Document CLASS/Library

      • Gdataxml:dom analysis, developed by Google, based on LIBXML2

      • Nsxmlparser:sax the method of analysis, making it relatively simple

        3. Example: Parsing XML with gdataxml? Documents and configurations:

        A. gdataxml/folder guide into Xcode project
        B. "Header Search Paths" in Build setting add/usr/include/libxml2c. "Other Linker Flags" in Build setting add-LXML2

Parsing Xml/json in iOS

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.