Nsjsonserialization parsing json file with system's own

Source: Internet
Author: User

1 #import "ViewController.h"2 #import "Student.h"3 #import "GDataXMLNode.h"4 #import "JSONKit.h"5 6 @interfaceViewcontroller () <NSXMLParserDelegate>7 8 /**9 * An array of stored dataTen  */ One@property (nonatomic, strong) Nsmutablearray *DataArray; A  - @end -  the @implementationViewcontroller -  -- (void) Viewdidload { - [Super Viewdidload]; +     //additional setup after loading the view, typically from a nib. - } +  A #pragmaMark-JSON data parsing from the system at-(Ibaction) Foundationparseractionjsondocument: (UIButton *) Sender { -      -     //1. Get the file path -NSString *path = [[NSBundle mainbundle] Pathforresource:@"Studentinfo_json.txt"Oftype:nil]; -      -      in     //2. Get NSData by Path -NSData *data =[NSData Datawithcontentsoffile:path]; to  +      -     //3. Initialize an array of stored data theSelf.dataarray =[Nsmutablearray array]; *      $     Panax Notoginseng     //4. Start the parsing -Nsarray *resultarray =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil]; the      +      A     //5. Iterate through the array and assign a value to the object using KVC the      for(Nsdictionary *dictinchresultarray) { +          -Student *stu =[[Student alloc] init]; $          $         //assigns a value from an array to an object - [Stu Setvaluesforkeyswithdictionary:dict]; -          the         //to add an object to an array - [Self.dataarray Addobject:stu];Wuyi     } the      -      Wu     //Traverse Inspection -      for(Student *stuinchSelf.dataarray) { AboutNSLog (@"name =%@, gender =%@, age =%ld, hobby =%@", Stu.name, Stu.gender, Stu.age, stu.hobby); $     } -      - } -  A @end

Nsjsonserialization parsing json file with system's own

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.