休息套件。如何 post NSObject 中的 NSDictionary
Restkit. How to post NSDictionary inside NSObject
我想在 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 的对象列表。
感谢您的帮助。
帮助这个:
[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]];
}];
我想在 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 的对象列表。
感谢您的帮助。
帮助这个:
[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]];
}];