IOS reads the local json/plist file

Source: Internet
Author: User

First, the general local can store lightweight data storage plist This is mainly the operation of the dictionary

Here's how:

NSString * samplefile= [[[NSBundle Mainbundle] Bundlepath] stringbyappendingpathcomponent:@ "sections_ Auth=4.plist"nsdictionary*  dic_sections = [nsdictionary Dictionarywithcontentsoffile:samplefile];

Second, sometimes the JSON structure can also be used to parse this does not limit the dictionary, arrays are supported

Here's how:

NSString *samplefile = [[[NSBundle Mainbundle] bundlepath] stringbyappendingpathcomponent:@ "file.json"]; NSString *jsonstring = [NSString stringwithcontentsoffile:samplefile encoding:nsutf8stringencoding Error:nil]; nsdictionary * dic_sections = [jsonstring objectfromjsonstring];//get all the contents of the File.json eg:  File.json contents as follows {    "Data": [             [              "No"              ],             [              "Information 001", "Data              002",              "information 003"              ],             [              "Information 001"              ],             [              "Information 001",              "Data 002",              "Information 003",              "Data 004"              ]             ],    "head": [             "Confidentiality responsibility ",             " contract ",             " Enterprise Information ",             " training materials "             ]}

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.