2013-01-17 5 views
8

RestKit 0.20.0から始めています。フォーマットが整ったJSONリクエストを作成するのに問題があります。RestKit 0.20 POST本体でGETスタイルリクエストとしてJSONオブジェクトがシリアル化されています

私は(残りキットログから)これを取得:

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" 
     } 
    ] 
} 

私が持っています2つの主要なオブジェクト:DLPointオブジェクトのNSSetを含むDLWalk(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]; 

そこで質問です:なぜ私は私のPOST本体に通常見てJSONオブジェクトを取得していないのですか?

答えて

14

あなたがrequest.bodyとして取得するものは、RESTKitのデフォルトの動作であり、通常正常に動作するURLエンコードされています。あなたはそれがJSONエンコードになりたい場合は

、ただ、これに関する詳細については、クエリ

manager.requestSerializationMIMEType=RKMIMETypeJSON; 

を投稿する前に、この行を挿入しRKObjectManagerクラスのAPIドキュメントにそこを見て: requestSerializationMIMEType

+0

シンプルなので、私はそれを逃したと信じられない!ありがとう! – codemonkey

関連する問題