我有两节课
=== 人 ====
@protocol People @end
@interface People : JSONModel
@property (strong, nonatomic) NSString *id;
@property (strong, nonatomic) NSString *userName;
@end
=== 人容器 ====
@interface PeopleContainer : JSONModel
@property (strong, nonatomic) People *people;
@end
代码在这一行失败:
PeopleContainer *peopleContainer = [[PeopleContainer alloc] initWithDictionary:peopleContainerDict error:&err];
给出错误:
*** Terminating app due to uncaught exception 'Type not allowed', reason: 'Account type not supported for ChatRoomContainer.account'
*** First throw call stack: (0x2243012 0x1725e7e 0x34e90 0x76ef5 0xf18cf8 0xe8075a 0xe4e453 0xe4e164 0xedaa31 0x50fe53f 0x5110014 0x51012e8 0x5101450 0x53d9e72 0x53c1daa) libc++abi.dylib: terminate called throwing an exception
问题是它在 iOS >7 上运行良好,但在 iOS 6.1 上运行良好(我已经在模拟器和设备上测试过)。
有人可以帮忙吗?
编辑:
这是帐户类
#import <Foundation/Foundation.h>
#import "JSONModel.h"
@protocol Account @end
@interface Account : JSONModel
@property (strong, nonatomic) NSString *id;
@property (strong, nonatomic) NSString *userName;
@property (strong, nonatomic) NSString *emailAddress;
@property (strong, nonatomic) NSString *password;
@property (strong, nonatomic) NSString *phoneNumber;
@end
另一个类 CHAT ROOM CONTAINER 包含 ACCOUNT CLASS
#import "JSONModel.h"
#import "Account.h"
#import "Friend.h"
#import "ChatRoom.h"
@interface ChatRoomContainer : JSONModel
@property (strong, nonatomic) Account *account;
@property (strong, nonatomic) NSArray<ChatRoom> *chatRooms;
@property (strong, nonatomic) NSArray<Friend> *friends;
@end
我使用向我们的服务器发送请求
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error)
{
if (completion) {
if (!error) {
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSDictionary *errorDict = [responseDict objectForKey:@"error"];
NSDictionary *warningDict = [responseDict objectForKey:@"warning"];
NSDictionary *result = [responseDict objectForKey:@"result"];
NSLog(@"RESULT\n====\n%@\n====\n",responseDict);
if(errorDict != nil && ![[NSNull null] isEqual:errorDict]) {
NSError* err = nil;
CustomError *error = [[CustomError alloc] initWithDictionary:errorDict error:&err];
completion(NO, nil, error, nil);
} else {
NSDictionary *chatRoomContainerDict = [result objectForKey:@"chatRoomContainer"];
NSError* err = nil;
ChatRoomContainer *chatRoomContainer = [[ChatRoomContainer alloc] initWithDictionary:chatRoomContainerDict error:&err];
if(!err) {
CustomWarning *warning = [[CustomWarning alloc] initWithDictionary:warningDict error:&err];
completion(!error, chatRoomContainer, nil, warning);
} else {
NSLog(@"ERROR WHILE PARSING CHAT ROOM CONTAINER JSON DICT!!! %@", [err userInfo]);
completion(!error, nil, nil, nil);
}
}
} else {
if(![AuxiliaryHelper connectedToInternet]) {
NSLog(@"NO INTERNET CONNECTION");
completion(NO, nil, [[CustomError alloc] initWithErrorType:ErrorTypeNoInternetConnection], nil);
} else {
DLog(@"INTERNAL SERVER ERROR!!!");
completion(NO, nil, [[CustomError alloc] initWithErrorType:ErrorTypeInternalServerError], nil);
}
}
}
}];