8
我剛剛開始使用RestKit 0.20.0,並且無法創建格式良好的JSON請求。RestKit 0.20 JSON對象正在序列化爲GET主體中的GET樣式請求
我得到這個(從靜止包日誌):
request.body=title=A%20glorious%20walk%20in%20the%20woods&startDateTime=2013-01-13%2016%3A09%3A33%20%2B0000&endDateTime=2013-01-13%2016%3A09%3A43%20%2B0000&points[][longitude]=-122.0307725&points[][latitude]=37.3310798&points[][longitude]=-122.0307334&points[][latitude]=37.33154242&points[][longitude]=-122.03075743&points[][latitude]=37.33138305&points[][longitude]=-122.03075659&points[][latitude]=37.33131185&points[][longitude]=-122.03057969&points[][latitude]=37.33156519&points[][longitude]=-122.03075535&points[][latitude]=37.33144466&points[][longitude]=-122.03076342&points[][latitude]=37.33123666&points[][longitude]=-122.03074488&points[][latitude]=37.33149482&points[][longitude]=-122.03068145&points[][latitude]=37.33155419&points[][longitude]=-122.03062909&points[][latitude]=37.33156564&points[][longitude]=-122.03076853&points[][latitude]=37.33115792
時,我想這(用花括號正常JSON對象和分財產的數組):
{
title: "Something",
startDateTime: "dateinfo",
endDateTime: "moredateinfo",
points: [
{
latitude: "37.33131313",
longitude: "122.4325454"
},
{
latitude: "37.33131313",
longitude: "122.4325454"
}
]
}
我有兩個主要對象:一個DLWalk比包含一個DLSS對象的NSSet(它們是CoreData對象,但此刻我忽略它,只關注創建HTTP請求)
這裏是c ODE我使用創建我的要求:
// Point mapping
RKObjectMapping *mappingPoint = [RKObjectMapping requestMapping];
[mappingPoint addAttributeMappingsFromArray:@[@"latitude", @"longitude"]];
RKRequestDescriptor *reqDescPoint = [RKRequestDescriptor requestDescriptorWithMapping:mappingPoint objectClass:[DLPoint class] rootKeyPath:nil];
// Walk mapping
RKObjectMapping *mappingWalk = [RKObjectMapping requestMapping];
[mappingWalk addAttributeMappingsFromArray:@[@"endDateTime", @"startDateTime", @"title"]];
RKRequestDescriptor *reqDescWalk = [RKRequestDescriptor requestDescriptorWithMapping:mappingWalk objectClass:[DLWalk class] rootKeyPath:nil];
// Define the relationship mapping
[mappingWalk addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"points" toKeyPath:@"points" withMapping:mappingPoint]];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://192.168.1.10:8080"]];
[manager addRequestDescriptor:reqDescWalk];
[manager addRequestDescriptor:reqDescPoint];
[manager addResponseDescriptor:responseDescriptor];
// POST to create
[manager postObject:walk path:@"/walk/save" parameters:nil success:nil failure:nil];
所以,問題是:爲什麼我不能在我的崗位的身體得到一個正常的找JSON對象?
太簡單了,不敢相信我錯過了!謝謝! – codemonkey