【发布时间】:2018-12-15 21:02:26
【问题描述】:
基于the accepted answer to this answer,我正在尝试通过 JSON 将一组自定义对象发送到服务器。
但是,以下用于序列化对象的代码会崩溃。我认为是因为 NSJSONSerialization 只能接受 NSDictionary,不能接受自定义对象。
NSArray <Offers *> *offers = [self getOffers:self.customer];
//Returns a valid array of offers as far as I can tell.
NSError *error;
//Following line crashes
NSData * JSONData = [NSJSONSerialization dataWithJSONObject:offers
options:kNilOptions
error:&error];
谁能建议将自定义对象数组转换为 JSON 的方法?
【问题讨论】:
标签: ios objective-c json nsjsonserialization