【发布时间】:2013-06-23 09:23:19
【问题描述】:
我在发布到我的服务器时遇到问题。每个值都被解析,但我的数组的属性名不是。
我的服务器期待这样的事情:
{ “位置”:2, "_id": "517808546b496658c10209", “产品”: [ { “金额”:3, “总”:6.6, “名称”:“可乐”, “价格”:2.2 },{ “金额”:1, “总”:4.0, “名称”:“水”, “价格”:2 } ] }
但是我的客户正在发送这个:
{ “位置”:2, "_id": "517808546b496658c10209", “产品”: [ 3、 6.6, “可乐”, 2.2, 1、 4.0, “水”, 2 ] }
产品:
@property (nonatomic) NSNumber *_id;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *detail;
@property (nonatomic, assign) float price;
@property (nonatomic, strong) Category *category;
@property (nonatomic, assign) int amount;
@property (nonatomic, assign) float total;
我的代码:
RKObjectMapping *productMapping = [RKObjectMapping requestMapping];
[productMapping addAttributeMappingsFromDictionary:@{@"productId":@"_id",@"amount":@":amount",@"total":@"total",@"price":@"price",@"name":@"name"}];
RKObjectMapping *horecaMapping = [RKObjectMapping requestMapping];
[horecaMapping addAttributeMappingsFromDictionary:@{ @"Id": @"_Id",@"deliverySpotId":@"location"}];
[horecaMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"self.getBasketSet" toKeyPath:@"products" withMapping:productMapping]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:horecaMapping objectClass:[Horeca class] rootKeyPath:nil];
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:baseURL];
[manager addRequestDescriptor:requestDescriptor];
[manager postObject:sharedHoreca path:@"/orders" parameters:nil success:nil failure:nil];
--更新 1-- 我也尝试为我的数组制作一个 NSSET ,但这仍然对我没有帮助。 (nsarray to nsset restkit)
【问题讨论】:
-
日志中是否有任何错误?
-
不,我没有收到任何错误。
标签: ios mapping nsarray restkit restkit-0.20