IOS development: Official built-in JSON

Source: Internet
Author: User

Apple provides json-related processing APIs for ios5, the most important of which is the NSJSONSerialization class.

 + (BOOL)isValidJSONObject:(  + (NSData *)dataWithJSONObject:()obj options:(NSJSONWritingOptions)opt error:(NSError **  + ()JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;

The most common method is the above three class methods.

The first one is used to determine whether the current data can be converted to JSON,

The second is to convert the data into JSON and return NSData,

The third is to parse JSON.

Example:

     NSMutableDictionary *dictionary =     [dictionary setValue: forKey:     [dictionary setValue: forKey:     NSArray *otherValueArray = @[, , ,      [dictionary setValue:otherValueArray forKey:          NSError *error =               NSData *jsonData =                                                           error:&               NSLog(           NSString *jsonString =                resultString =                                                          error:&               NSLog(           NSArray *navigatorArray = resultString[          NSLog(           jsonString, resultString, navigatorArray);

 

NSLog output result:

 

By the way,Can be used.
According to tests by netizens, this built-in resolution efficiency is faster than several third-party JSON libraries on the Internet.

 

 

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.