0

I'm finding it difficult to deal with a webservice that has a top level array with no keypath and the array contains only strings, i.e.:

["foo", "bar", "baz"]

It would be easy to map if it were something like:

{"array_of_strings": ["foo", "bar", "baz"]} 

I thought perhaps having a nil keyPath and mappingForClass:[NSString class] might do the trick, but it didn't seem to (I'm not sure that mapping for NSString even makes sense, but thought it might be a special case RestKit could handle).

1 Answer 1

1

You need to use a nil key path, but you're expected to map into an object where the string is an attribute. Something like:

RKEntityMapping *objectMapping = [RKEntityMapping mappingForEntityForName:...];
[objectMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"name"]];
objectMapping.identificationAttributes = @[ @"name" ];

If you just want to map into an array of strings then you don't need RestKit and you should just use AFJSONRequestOperation.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah good call, I was doing the rest of my web services requests with RestKit and didn't even think to just use AFNetworking for this simple request. Great point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.