1

I've got an issue with posting an array of strings to the server:

My Mapping is this:

+(RKMapping*)occurrenceCreateMapping {

    RKObjectMapping *occurrenceCreateMapping = [RKObjectMapping requestMapping];

    [occurrenceCreateMapping addAttributeMappingsFromDictionary:@{
     @"observedOn" :@"ObservedOn",
     @"latitude" :@"Latitude",
     @"longitude" :@"Longitude",
     @"address" :@"Address",
     @"host" :@"Host",
     @"pests" : @"Pests",
     @"networkId" :@"NetworkId",
     @"consignmentNumber" :@"ConsignmentNumber"
     }];

    return occurrenceCreateMapping;
}

But what is actually getting posted is this:

Post from Charles proxy

Which is invalid because my server side model binder is expecting a single array of strings.

This is the code for my OccurrenceCreate Class:

@interface BBOccurrenceCreate : NSObject

@property (nonatomic, retain) NSDate *observedOn;

@property CGPoint location;

@property (nonatomic, retain) NSString  *latitude,
                                        *longitude,
                                        *address,
                                        *host,
                                        *consignmentNumber,
                                        *networkId;

@property (nonatomic,retain) NSArray *pests;

@end

Can anyone help me map this array of strings to a json array? I'm thinking this should be simple ?!?!

4

1 回答 1

1

You're probably missing the serialisation type setting so RestKit is defaulting to form-url-encoded. Explicitly set the serialisation type to instruct RestKit to generate JSON.

于 2013-09-26T06:57:23.053 回答