我利用休息室把制造行动张贴到我的铁路申请中。 我为特性绘制地图:
- (void) initCustomerMapping
{
RKObjectMapping *customerSerializationMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[customerSerializationMapping mapKeyPath:@"id" toAttribute:@"id"];
[customerSerializationMapping mapKeyPath:@"lastname" toAttribute:@"lastname"];
[customerSerializationMapping mapKeyPath:@"firstname" toAttribute:@"firstname"];
[customerSerializationMapping mapKeyPath:@"house_name" toAttribute:@"house_name"];
[customerSerializationMapping mapKeyPath:@"sci" toAttribute:@"sci"];
[customerSerializationMapping mapKeyPath:@"water_used" toAttribute:@"water_used"];
[customerSerializationMapping mapKeyPath:@"address_line_1" toAttribute:@"address_line_1"];
[customerSerializationMapping mapKeyPath:@"address_line_1" toAttribute:@"address_line_2"];
[customerSerializationMapping mapKeyPath:@"postal_code" toAttribute:@"postal_code"];
[customerSerializationMapping mapKeyPath:@"city" toAttribute:@"city"];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:customerSerializationMapping forClass:[Customer class]];
}
i 发出请求:
Customer* customer = [[Customer alloc] init];
customer.lastname = lastname.text;
customer.firstname = firstname.text;
customer.house_name = house_name.text;
customer.sci = sci.text;
customer.water_used = water_used.text;
customer.address_line_1 = address_line_1.text;
customer.address_line_2 = address_line_2.text;
customer.postal_code = postal_code.text;
customer.city = city.text;
[[RKObjectManager sharedManager] postObject:customer delegate:self];
但json派人看着:
{"water_used"=>"710", "house_name"=>"test", "address_line_1"=>"test", "city"=>"test", "sci"=>"546", "firstname"=>"test", "lastname"=>"test", "address_line_2"=>"test", "postal_code"=>"75896"}
并且希望:
{ "customer" =>
{"water_used"=>"710", "house_name"=>"test", "address_line_1"=>"test", "city"=>"test", "sci"=>"546", "firstname"=>"test", "lastname"=>"test", "address_line_2"=>"test", "postal_code"=>"75896"}
}
怎么会混淆呢? 我尝试使用forKey,但一经失败
http://www.ohchr.org。
也可以使用:
[[RKObjectManager sharedManager].mappingProvider registerMapping:customerSerializationMapping withRootKeyPath:@"customer"];