Data analysis of iOS learning

Source: Internet
Author: User

Parsing: The process of extracting data according to a well-agreed format is called parsing; Background developers in the agreed-upon format to the data, the front-end developers in accordance with the agreed format to read data; Mainstream format: Xml/json front-end and background can be recognized format; XML parsing XML analysis of two working principles: 1.SAX Analysis: Based on the event callback parsing mechanism, line-by-row analysis, low efficiency, suitable for big data analysis. The system provides NSXMLPARSER.2.DOM parsing: Read the parsing data into the memory, initialize the tree structure, and parse it by layer. High efficiency, suitable for small data analysis.  Google offers the Gdataxmlnode. Parsing tools: Gdataxmlnode is an open source C-based libxml2.dylib dynamic link library provided by Google, which encapsulates the XML parsing class of OC, which is more efficient. The principle of DOM parsing is adopted. Using Gdataxml nod step: 1.target-build phases-link Binary Add libxml2.dylib2.target-build setting-search Header Sear CH Path adds the difference between/USR/INCLUDE/LIBXML2 Libxml2.dylib and Libxml2.2.dylib: The former is a shortcut, always pointing to the newest class library, and the latter is the real class library, using the former has a benefit when the class library is updated , our older version of the project does not need to re-import the new class library. JSON parsing: Jsonkit is to add the parsing function by adding the form of classification to NSString, NSData.
//system-Provided parsing JSON method- (void) Handlesystemparser: (Uibarbuttonitem *) Item {//1. Get the file pathNSString *filepath = [[NSBundle mainbundle] Pathforresource:@"Student"OfType:@"JSON"]; //2. Initialize the NSData object according to the path of the fileNSData *data =[NSData Datawithcontentsoffile:filepath]; //parsingNsarray *arr =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; NSLog (@"%@", arr);}

//third-party class library parsing JSON method (use Jsonkit here)- (void) Handlethirdpartparser: (Uibarbuttonitem *) Item {//Convert JSON format data to OC object (NSString object)

//1. Get the file pathNSString *filepath = [[NSBundle mainbundle] Pathforresource:@"Student"OfType:@"JSON"]; //2. Initializing a String object based on the path of a fileNSString *datastr =[NSString Stringwithcontentsoffile:filepath encoding:nsutf8stringencoding Error:nil]; //3. Parse into OC object. (Mutable object/immutable Object)Nsarray *ARR1 =[Datastr objectfromjsonstring]; Nsarray*ARR2 =[Datastr mutableobjectfromjsonstring]; NSLog (@"%@", arr1); NSLog (@"%@", ARR2);

}

Of course, can also parse into NSData object, the first step method is the same, get the file path

- (void) Handlethirdpartparser: (Uibarbuttonitem *) Item {//Convert JSON format data to OC object (NSData object)//1. Get the file pathNSString *filepath = [[NSBundle mainbundle] Pathforresource:@"Student"OfType:@"JSON"]; //Initialize to NSData object based on file pathNSData *data =[NSData Datawithcontentsoffile:filepath]; //parsing. (variable/immutable)Nsarray *ARR1 =[Data objectfromjsondata]; Nsmutabledata*ARR2 = [data mutableobjectfromjsondata];

These are the objects that convert the JSON data to OC, and the following is a way to convert the OC object to JSON data.

    //converts the OC object into JSON-formatted data. //1. Convert the OC Array object to JSON format data.Nsarray *arr1 = @[@"AA",@"BB",@"cc",@"DD"]; NSData*jsondata1 = [arr1 jsondata];//turn into JSON format dataNSString *jsonstr1 = [arr1 jsonstring];//turn into JSON format string//2. Convert the OC Dictionary object to JSON format data.Nsdictionary *dic2 = @{@"name":@"Frank",                           @" Age":@" -"                           }; NSData*JSONDATA2 = [Dic2 jsondata];//turn into JSON format dataNSString *JSONSTR2 = [Dic2 jsonstring];//turn into JSON format string

Data analysis of iOS learning

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.