The pitfalls in the AFN parser, the AFN parser

Source: Internet
Author: User

The pitfalls in the AFN parser, the AFN parser

The AFN framework is used to send network requests. It can automatically parse JSON data and send request with parameters.
The AFN framework can also monitor the current network status and support HTTPS requests. The classes used are AFNetworkReachabilityManager and AFSecurityPolicy.

Although AFN can send requests, there are many pitfalls in it,
1. to get the correct JSON data, you must: The network request is successful, the server must return JSON data, And You (AFN) can also parse the data, that is, the request you sent, the returned data type must be JSON data and end with JSON data. This is required because only the data types recognized by the parser include application/json, text/json, text/javascript.
2. AFN has three types of Resolvers. The default is the JSON parser and the omnipotent parser. It can't do anything because it returns all the data as binary data, you have to resolve it yourself.
3. The biggest headache is parsing XML data. AFN also has an XML parser, but it only returns a parser that has to be parsed by itself.
If you change the parser type, the returned data type will change. refer to the following:
1. JSON Parser: Return JSON parsed data. ------ JSON
2. XML Parser: NSXMLParser is returned ------ XML/the default is SAX parsing.
3. omnipotent Parser: returns NSData data. ----- JSON/XML/HTML/various files...
For file/image/Video/Webpage HTML, you can only select the omnipotent parser!

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.