【发布时间】:2012-05-15 15:57:07
【问题描述】:
我有一点 json 编码问题:
在将对象格式 JSON 发送到 php 服务器之前,我需要使用 SBJSON 对其进行编码 目前此示例代码有效:
NSArray *arrayData = [NSArray arrayWithObjects:
user.id == nil ? [NSNumber numberWithInt:-1] : user.id,
ProfessionField.text, NameField.text, RPPSField.text, RPPSField.text,
NameField.text, SurnameField.text, StreetField.text,
TownField.text, CpField.text, MailField.text,
PhoneField.text, FaxField.text, MobileField.text,
// [user.horaires JSONRepresentation],
nil];
NSArray *arrayKey = [NSArray arrayWithObjects:
@"id", @"spe", @"name", @"rpps", @"cip",
@"name", @"surname", @"rue",
@"ville", @"cp", @"mail",
@"tel", @"fax", @"port",
// @"horaires",
nil];
NSDictionary *dataBrut = [NSDictionary dictionaryWithObjects:arrayData forKeys:arrayKey];
NSDictionary *jsonDict = [NSDictionary dictionaryWithObject:dataBrut forKey:@"data"];
NSString *jsonRequest = [jsonDict JSONRepresentation];
问题是当我需要发送“user.horaires”(这里是评论) 此对象的 JSON 表示中的应用程序崩溃。
此对象是以下类的数组:
@interface Horaire : NSObject
{
BOOL morning;
}
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) NSString *open;
@property (nonatomic, strong) NSString *close;
有人知道如何成功编码吗?
【问题讨论】:
标签: objective-c ios json sbjson