JSONModel Source Code Reading Notes

Source: Internet
Author: User

JSONModel is a database that parses the Json data returned by the server.

Generally, the json data returned by the server is converted to the Model by writing a data conversion module, and the NSString data is converted to the Data Type of the property in the Model.

In this way, if you want to modify the server, you may need to modify two or three files.

The emergence of JSONModel is to complete this resolution at the design level.

Usage: Reference connection

JSONModel. m, the core part of its source code, is read as follows:
In

Function: returns nil if any errors or errors occur.

-()initWithDictionary:(NSDictionary*)dict error:(NSError**     (! (err) *err =     (![dict isKindOfClass:[NSDictionary  (err) *err =    self = (!         (err) *err =    NSArray* incomingKeysArray =* requiredProperties =* incomingKeys =    JSONKeyMapper* keyMapper =            NSMutableSet* transformedIncomingKeys =* transformedName =         (NSString* requiredPropertyName             transformedName =                    incomingKeys =     (!        JMLog( (err) *err =    incomingKeys==     (JSONModelClassProperty* property         NSString* jsonKeyPath = (keyMapper) jsonKeyPath =         jsonValue =         (jsonValue==nil && property.isOptional==                    Class jsonValueClass = [jsonValue = (Class allowedType = (isValueOfAllowedType==            JMLog( (err) *err =                     (property.type == nil && property.structName==                                         ([[property.type ] isSubclassOfClass:[JSONModel                 NSError* initError = value = [[property.type alloc] initWithDictionary: jsonValue error:& (! (initError && err) *err =                                                    jsonValue = (! (err) *err =                 (property.isStandardJSONType &&                    =                                    (![jsonValue isKindOfClass:property.type] && !||                                        Class sourceClass = [JSONValueTransformer classByResolvingClusterClasses:[jsonValue                     NSString* selectorName = [NSString stringWithFormat:? property.structName : property.type),                                               sourceClass];                     SEL selector =                     clang diagnostic push clang diagnostic ignored "-Warc-performSelector-leaks"                                                jsonValue = clang diagnostic pop                         [NSException exceptionWithName:, property.type, [self     NSError* validationError == [self validate:& (doesModelDataValidate == (err) *err =    








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.