2

RestKit に問題がある

パラメータの文字列配列を送信しようとしています。このようにしています。

RKObjectMapping* tagMapping = [[RKObjectManager sharedManager].mappingProvider
    objectMappingForClass:[RKTag class]];
NSArray *tags = [NSArray arrayWithObjects:@"Home", @"Relation", nil];
NSDictionary *dictParams =
    [NSDictionary dictionaryWithObject:tags forKey:@"type"];

NSString *resourcePath = [[NSString stringWithString:@"/tags"]
    stringByAppendingQueryParameters:dictParams];
[_m loadObjectsAtResourcePath:resourcePath usingBlock:^(RKObjectLoader *loader) {
    [loader setObjectMapping:tagMapping];
    [loader setMethod:RKRequestMethodGET];
    [loader setDelegate:delegate];
}];

しかし、サーバー上のコンソールを見ると、

GET "/tags?type%5B%5D=%D0%A0%D0%BE%D0%B4%D1%81%D1%82%D0%B2%D0%B5%D0%BD%D0%BD%D1を開始しました127.0.0.1 の場合は %8B%D0%B5%20%D0%BE%D1%82%D0%BD%D0%BE%D1%88%D0%B5%D0%BD%D0%B8%D1%8F" 2012-05-11 16:30:54 +0400 TagsController#index による処理 JSON パラメータ: {"type"=>["Home"]}

RKObjectLoader が初期化するとき、メソッド loaderWithResourcePath を呼び出します。何が配列を切り捨てますか

修正方法は?

4

1 に答える 1

0

RKUrlClass を変更することでこの問題を解決します

- (id)initWithBaseURL:(NSURL *)theBaseURL resourcePath:(NSString *)theResourcePath queryParameters:(NSDictionary *)theQueryParameters {
    NSDictionary *resourcePathQueryParameters = [theResourcePath queryParameters];
    NSMutableDictionary *mergedQueryParameters = [NSMutableDictionary dictionaryWithDictionary:[theBaseURL queryParameters]];
    [mergedQueryParameters addEntriesFromDictionary:resourcePathQueryParameters];
    [mergedQueryParameters addEntriesFromDictionary:theQueryParameters];

    // Build the new URL path
    NSRange queryCharacterRange = [theResourcePath rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"?"]];
    NSString *resourcePathWithoutQueryString = (queryCharacterRange.location == NSNotFound) ? theResourcePath : [theResourcePath substringToIndex:queryCharacterRange.location];
    NSString *baseURLPath = [[theBaseURL path] isEqualToString:@"/"] ? @"" : [[theBaseURL path] stringByStandardizingPath];
    NSString *completePath = resourcePathWithoutQueryString ? [baseURLPath stringByAppendingString:resourcePathWithoutQueryString] : baseURLPath;
    NSString* completePathWithQuery = [completePath stringByAppendingQueryParameters:mergedQueryParameters];

    // before
    //    NSURL* completeURL = [NSURL URLWithString:completePathWithQuery relativeToURL:theBaseURL];
    // after my edit
    NSString *cPath = theResourcePath ? theResourcePath : baseURLPath;
    NSURL* completeURL = [NSURL URLWithString:cPath relativeToURL:theBaseURL];

    if (!completeURL) {
        RKLogError(@"Failed to build RKURL by appending resourcePath and query parameters '%@' to baseURL '%@'", theResourcePath, theBaseURL);
        [self release];
        return nil;
    }

    self = [self initWithString:[completeURL absoluteString]];
    if (self) {
        self.baseURL = theBaseURL;
        self.resourcePath = theResourcePath;
    }

    return self;
}
于 2012-05-15T05:59:35.307 に答える