当我通过Restkit POST一个映射模型时,结果Json看起来像这样,双打是字符串,我希望它们是双打的:
{
Coordinate = (
"39.2",
"-121.0"
);
}
我想:
{
Coordinate = (
39.2,
-121.0
);
}
这是我的映射
+(RKObjectMapping *)mapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]];
[mapping addAttributeMappingsFromArray:@[@"Coordinate"]];
return mapping;
}
设置Location对象的坐标时:
@interface MYLocationDTO : NSObject
@property (strong, nonatomic) NSArray *Coordinate;
+(RKObjectMapping *)mapping;
@end
我传入一个由两个nsnumber组成的数组,这些数字是从double值设置的。
任何人都知道如何将此nsarray集合发布为数字而非字符串? 谢谢!
这是我的帖子:
-(void)updateLocationOfUserWithLocationDTO:(WHMLocationDTO *)dto withCompletionBlock:(void (^)(BOOL, NSString *))callbackBlock
{
//whim-ios.herokuapp.com/users/password-reset
RKObjectManager *manager = [WHMDataController getManagerWithSession];
RKObjectMapping *requestMapping = [[WHMLocationDTO mapping] inverseMapping];
RKRequestDescriptor *requestDesc = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[WHMLocationDTO class] rootKeyPath:nil method:RKRequestMethodPOST];
[manager addRequestDescriptor:requestDesc];
RKObjectMapping *responseMapping = [WHMResponseMapping responseMapping];
RKDynamicMapping *dynamicMapping = [WHMResponseMapping createDynamicMappingWithResponseMapping:responseMapping];
[manager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping method:RKRequestMethodPOST pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
//POST
__weak __typeof__(self) weakSelf = self;
[manager postObject:dto
path:@"user/loc"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *result)
{
答案 0 :(得分:0)
为什么不使用Apple的API生成JSON,如本文所示:http://www.raywenderlich.com/5492/working-with-json-in-ios-5 并只发布JSON?