休息套件。如何在 NSObject 中发布 NSDictionary
Posted
技术标签:
【中文标题】休息套件。如何在 NSObject 中发布 NSDictionary【英文标题】:Restkit. How to post NSDictionary inside NSObject 【发布时间】:2016-10-03 10:05:49 【问题描述】:我想在 request.body 中达到以下结果 CarwashForm[工作模式][1][状态]=1
其中 [1] 是对象的 id
@interface WorktimeForm : NSObject
@property(nonatomic,copy) NSNumber *isset;
@property(nonatomic,copy) NSNumber *weekday;
@property(nonatomic,copy) NSNumber *status;
@property(nonatomic,copy) NSString *work_from;
@property(nonatomic,copy) NSString *work_to;
@end;
@interface CarwashForm : NSObject
@property(nonatomic,copy) NSString *name;
@property(nonatomic,copy) NSString *address;
@property(nonatomic,copy) NSNumber *latitude;
@property(nonatomic,copy) NSNumber *longitude;
@property(nonatomic,copy) NSArray<NSString*> *files;
@property NSDictionary *workmode;
@end
截图http://joxi.ru/4AkOO4kiMvQ4aA中的映射代码。我使用不同的情况(用于数组、字典、nsset)但无法获得合适的结果
NSDictionary *workmode
是具有键 ID 的对象列表。
感谢您的帮助。
【问题讨论】:
【参考方案1】:帮助:
[delegate startProgress];
self.manager.requestSerializationMIMEType = @"application/x-www-form-urlencoded";
NSMutableDictionary *dtPost = [NSMutableDictionary new];
[dtPost setObject:carwash.name forKey:@"CarwashForm[name]"];
[dtPost setObject:carwash.address forKey:@"CarwashForm[address]"];
[dtPost setObject:carwash.latitude forKey:@"CarwashForm[latitude]"];
[dtPost setObject:carwash.longitude forKey:@"CarwashForm[longitude]"];
for (WorktimeForm* wt in carwash.workmode)
[dtPost setObject:wt.status forKey:[NSString stringWithFormat:@"CarwashForm[workmode][%@][isset]",wt.weekday]];
[dtPost setObject:wt.status forKey:[NSString stringWithFormat:@"CarwashForm[workmode][%@][status]",wt.weekday]];
[dtPost setObject:wt.work_from forKey:[NSString stringWithFormat:@"CarwashForm[workmode][%@][work_from]",wt.weekday]];
[dtPost setObject:wt.work_to forKey:[NSString stringWithFormat:@"CarwashForm[workmode][%@][work_to]",wt.weekday]];
[self.manager postObject:dtPost path:[NSString stringWithFormat: @"carwash/%d",[id_wash intValue]] parameters:dtPost success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
NSLog(@"%@",@"OK saveCarwash");
[delegate success:200 toPack:mappingResult toMsg:@"success"];
[delegate stopProgress];
failure:^(RKObjectRequestOperation *operation, NSError *error)
NSLog(@"%@",@"ERROR saveCarwash");
[delegate stopProgress];
[delegate fail:500 toMsg:[error localizedFailureReason]];
];
【讨论】:
以上是关于休息套件。如何在 NSObject 中发布 NSDictionary的主要内容,如果未能解决你的问题,请参考以下文章