nsnumbers 数组的 Reskit POST 生成字符串 JSON 字段
Posted
技术标签:
【中文标题】nsnumbers 数组的 Reskit POST 生成字符串 JSON 字段【英文标题】:Reskit POST of array of nsnumbers makes string JSON fields 【发布时间】:2014-08-20 17:16:11 【问题描述】:当我通过 Restkit 发布映射模型时,生成的 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)
【问题讨论】:
【参考方案1】:为什么不使用 Apple 的 API 来生成 JSON,如本文所示:http://www.raywenderlich.com/5492/working-with-json-in-ios-5 只需 POST JSON?
【讨论】:
可能是因为 RESTKit 为您做到了。 是的.. Restkit 应该为你做价值转换。 如果只是将其转换为字符串,并且您需要浮点数,您可能需要考虑另一种方法。以上是关于nsnumbers 数组的 Reskit POST 生成字符串 JSON 字段的主要内容,如果未能解决你的问题,请参考以下文章