美文网首页
JSON Accelerator自动生成代码注意问题

JSON Accelerator自动生成代码注意问题

作者: 我是小胡胡分胡 | 来源:发表于2017-12-15 15:11 被阅读28次

    JSON Accelerator自动生成代码注意问题

    一、注意assign

    @property (nonatomic, assign) id content;
    @property (nonatomic, assign) id time;
    @property (nonatomic, assign) id title;
    

    全是assign。 必然崩溃

        ////Printing description of ((NSISRestrictedToZeroMarkerVariable *)0x000060400064f3c0):
        //0x6040002803c0.marker{id: 614}
        //"title" : "收入了¥1,000",
    

    二、类型不匹配。
    总结:
    如果model是NSString,可能因为后台 string转number发生崩溃
    如果model是基本数据类型,后台可以string、number

    1、原先是number,现在转成string ,可以支持。

    后台返回的success的不管是string,还是number,都可以转换。
    @property (nonatomic, assign) BOOL success;

    NSDecimalNumber/NSNumber/NSValue/NSString 都有转化为基础数据类型的方法,boolValue,integerValue等等

    self.success = [[self objectOrNilForKey:kachievementAndRanklistSuccess fromDictionary:dict] boolValue];

    2、原先是string,现在转为number。 不支持

    @property (nonatomic, strong) NSString *msg;```
    
    后台返回的msg改为number后, model并没有变化。  仍然会被当作NSString来处理。但是实际上是nsnumber类型。如果此时调用nsstring的方法,会因为实际是nsnumber类型,而发生崩溃。
    
    • (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
      id object = [dict objectForKey:aKey];
      return [object isEqual:[NSNull null]] ? nil : object;
      }

    self.msg = [self objectOrNilForKey:kachievementAndRanklistMsg fromDictionary:dict];

    
    

    NSDecimalNumber类

    @property (readonly) double doubleValue;

    NSNumber类

    @property (readonly) char charValue;
    @property (readonly) unsigned char unsignedCharValue;
    @property (readonly) short shortValue;
    @property (readonly) unsigned short unsignedShortValue;
    @property (readonly) int intValue;
    @property (readonly) unsigned int unsignedIntValue;
    @property (readonly) long longValue;
    @property (readonly) unsigned long unsignedLongValue;
    @property (readonly) long long longLongValue;
    @property (readonly) unsigned long long unsignedLongLongValue;
    @property (readonly) float floatValue;
    @property (readonly) double doubleValue;
    @property (readonly) BOOL boolValue;
    @property (readonly) NSInteger integerValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
    @property (readonly) NSUInteger unsignedIntegerValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));

    @property (readonly, copy) NSString *stringValue;

    NSString类

    @property (readonly) double doubleValue;
    @property (readonly) float floatValue;
    @property (readonly) int intValue;
    @property (readonly) NSInteger integerValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
    @property (readonly) long long longLongValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
    @property (readonly) BOOL boolValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0)); // Skips initial space characters (whitespaceSet), or optional -/+ sign followed by zeroes. Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9. It ignores any trailing characters.

    //NSValue类
    @property (readonly) char charValue;
    @property (readonly) unsigned char unsignedCharValue;
    @property (readonly) short shortValue;
    @property (readonly) unsigned short unsignedShortValue;
    @property (readonly) int intValue;
    @property (readonly) unsigned int unsignedIntValue;
    @property (readonly) long longValue;
    @property (readonly) unsigned long unsignedLongValue;
    @property (readonly) long long longLongValue;
    @property (readonly) unsigned long long unsignedLongLongValue;
    @property (readonly) float floatValue;
    @property (readonly) double doubleValue;
    @property (readonly) BOOL boolValue;
    @property (readonly) NSInteger integerValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));
    @property (readonly) NSUInteger unsignedIntegerValue API_AVAILABLE(macos(10.5), ios(2.0), watchos(2.0), tvos(9.0));

    @property (readonly, copy) NSString *stringValue;

    
    
    

    相关文章

      网友评论

          本文标题:JSON Accelerator自动生成代码注意问题

          本文链接:https://www.haomeiwen.com/subject/prldwxtx.html