更新时间:2022-06-16 21:58:29
添加新的 initWithDictionary :
方法订单
:
- (instancetype)initWithDictionary:(NSDictionary*)dictionary {
if (self = [super init]) {
self.OrderId = dictionary[@"OrderId"];
self.Title = dictionary[@"Title"];
self.Weight = dictionary[@"Weight"];
}
return self;
}
不要忘记添加 initWithDictionary
签名到 Order.h
文件
Don't forget to add initWithDictionary
's signature to Order.h
file
在获得JSON的方法中:
In the method where you get JSON:
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *e;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:nil error:&e];
Order *order = [[Order alloc] initWithDictionary:dict];