1

シンプルな Json をサーバーに送信し、iPad アプリで Json 応答を取得したいと考えています。Restkit を使用してすべての作業を行っていますが、Json の POST に問題があります。これは、私が望む単純な Json リクエストです。

{"id_partita":"2"}

そして、応答は次のようになります。

[{"id":34,"id_dispositivo":"123","id_partita":2,"allenatore":0,"giocatore1":"AAA","giocatore2":"BBB",...}]

これはXcodeでの私のコードです:

-(void) post
{
    RKURL *baseURL = [RKURL URLWithBaseURLString:@"mysite"];
    RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];

    // Setup object mappings
    RKObjectMapping *formazioneMapping = [RKObjectMapping mappingForClass:[Formazione class]];

    [formazioneMapping mapKeyPath:@"id_formazione"
                                toAttribute:@"id_formazione"];
    [formazioneMapping mapKeyPath:@"id_dispositivo"
                                toAttribute:@"id_dispositivo"];
    [formazioneMapping mapKeyPath:@"id_partita"
                                toAttribute:@"id_partita"];
    [formazioneMapping mapKeyPath:@"formazione"
                                toAttribute:@"formazione"];
    [formazioneMapping mapKeyPath:@"giocatore1"
                                toAttribute:@"giocatore1"];
    [formazioneMapping mapKeyPath:@"giocatore2"
                                toAttribute:@"giocatore2"];
;

    // Register our mappings with the provider
    [objectManager.mappingProvider setMapping:formazioneMapping forKeyPath:@""];

    [objectManager.router routeClass:[Formazione class]
                      toResourcePath:@"/formazione/index.php"
                           forMethod:RKRequestMethodPOST];

    // Set serialization MIME type.
    [RKObjectManager sharedManager].serializationMIMEType = RKMIMETypeFormURLEncoded;

    // Configure a serialization mapping for our Formazione class. We want to send id_partita
    RKObjectMapping *formazionePOSTSerializationMapping = [RKObjectMapping
                                                      mappingForClass:[Formazione class]];
    [formazionePOSTSerializationMapping mapAttributes:@"id_partita", nil];

    // Now register the mapping with the provider
    [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:formazionePOSTSerializationMapping forClass: [Formazione class]];

    FormazionePOST *formazionePOST = [[FormazionePOST alloc] init];
    formazionePOST.id_partita = @"2";
    [[RKObjectManager sharedManager] postObject:formazionePOST delegate:self];

}

しかし、実行しようとすると、「HTTP メソッド 'POST' のタイプ 'FormazionePOST' のオブジェクトのルーティング可能なパスが見つかりません」というエラーが表示されます。

POST の簡単な例を見つけられず、Json を取得できません。助けてくれてありがとう!

4

2 に答える 2

0

ルーターの初期化で Formazione クラスを参照していますが、FormazionePost クラスを投稿しようとしていますか?

于 2012-11-01T17:28:48.437 に答える