Parse XML/JSON and iosjson in iOS

Source: Internet
Author: User
Tags xml example xml parser

Parse XML/JSON and iosjson in iOS

JSON Data Format

1. Overview:
JSON (JavaScript Object Notation) is a lightweight data exchange format for users.

Based on the plain text format, it is easy for the publisher to read and write, and easy for machine parsing and Token Generation.

2. JSON data is written in the format of name/value • The name is written in the front of the quotation mark (in double quotation marks)
• The value pair is written on the front
• The centers are separated by colons.

3. Supported JSON value types

  • Number (integer or floating point number)

  • String (in double quotation marks)

  • Logical value (true or false)

  • Array (in brackets)

  • Object (in curly brackets)

  • Null

JSON format layout 1: The outermost layer is the braces

Online JSON formatting ghost tool http://json.phpddt.com

URL:

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

JSON format: the outermost layer is brackets.

1. JSON value struct supports ing between types and OC objects

  • Number> NSNumber

  • Double quotation marks-> NSString

  • Brackets> NSArray

  • Large braces-> NSDictionary

  • Null-> NSNull

    2. Object-to-model conversion: converts parsed OC objects (NSArray/NSDictionary) to custom model classes of callback.

 

XML data format

1. XML (eXtensible Markup Language) eXtensible Markup Language,
• It is a markup language used to mark a notebook file to make it a structured markup language.
• XML is a commonly used language for data transmission between various login applications.

2. Three terms in the XML example document:

  • Root element: outermost Element

  • Element: the part from the start tag to the end tag.

  • Attribute: provides additional information about an element.

1. XML example Example 1:

2. XML Example 2:

1. XML parsing scheme:

  • DOM: Metadata loads the entire xml Parser file into the memory at a time. The element structure in the xml Parser file is used to parse the element pair

    Value/attribute

  • SAX: starts from the root element of the xml Parser document and parses the elements in sequence.

    2. parse XML Parser document classes/libraries in iOS

    • GDataXML: DOM parse method, developed by Google, based on libxml2

    • NSXMLParser: parses the statement using the SAX Parser method to make the parser relatively simple.

      3. Example: Use GDataXML to parse the xml Parser document. • Configuration:

      A. Import the GDataXML/logs folder to the xcode development project.
      B. Add "Other Linker Flags" in "Header Search Paths" in "Build Setting" to/usr/include/libxml2c. Build Setting to add-lxml2

Related Article

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.