解析後臺返回的json數據時,推薦使用MJExtension ,使用起來很方便
github:https://github.com/CoderMJLee/MJExtension
在AModel.h中
@property(nonatomic,strong)NSString *description;
出現提示warning:Auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it will be synthesized 'readonly' via another property
原因是因爲 compiler 讀取 sub-class 時,會發現 description 明明應該是個 readonly property(super-class 講的),但你卻要將它設爲 readwriteproperty,所以 compiler 不知道該怎麼 auto synthesis。
解決辦法:
AModel.m
@implementation AModel
@dynamic description;
@end
但是剛從後臺拿數據時,用MJExtension.h解析數據時,還是拿不到數據。
後臺返回的字典裏的字段是description,但是可以在model裏用Description來表示,大寫的D。
在AModel.m裏實現
+(NSDictionary *)replacedKeyFromPropertyName{
return@{@"Description":@"description"};
}
核心代碼:
AModel *subM = [AModelobjectWithKeyValues:dic];