我有这个对象:
@interface EmailToSend : NSObject
@property (copy, nonatomic) NSString *Subject;
@property (copy, nonatomic) NSString *Body;
@property (strong, nonatomic) NSArray *Cc;
@property (strong, nonatomic) NSArray *Bcc;
@property (strong, nonatomic) NSArray *To;
@property (strong, nonatomic) EmailAddress *From;
@property (copy, nonatomic) NSString *Username;
@property (copy, nonatomic) NSString *Password;
@end
Bcc, To, From as Array EmailAdress
@interface EmailAddress : NSObject
@property (nonatomic, assign) int Id;
@property (copy, nonatomic) NSString *address;
@property (copy, nonatomic) NSString *displayName;
@end
我使用 iOS 中的 JSON 框架来解析对象EmailToSend
:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:emailToSend options:NSJSONWritingPrettyPrinted error:&writeError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
当我运行项目时,出现一个错误:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Invalid type in JSON write
(EmailToSend)
如何解决?