DAN
DAN

Reputation: 939

RestKit - saving JSON content into a string coredata attribute

I need to parse a JSON web service response containing a key whose children are not known.

For example let's have the following JSON response where the keys of the customData attribute are defined at runtime:

{
    "score": 996,
    "customData": { "key1": "key1value", "key2": "key2value" },
    "isRegistered": true,
    "allowOpening": "OK"
}

Would it be possible to save the JSON content of customData into a string coredata attribute?

I've tried with a simple mapping like this:

RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:[[self class] description] inManagedObjectStore:managedObjectStore];
[mapping addAttributeMappingsFromDictionary:@{
                 @"score": @"score",
                 @"customData":@"customData",
                 @"isRegistered":  @"isRegistered",
                 @"allowOpening": @"allowOpening"}];

but it doesn't work, customData saved by coredata is always empty.

Many thanks, DAN

Upvotes: 1

Views: 76

Answers (1)

Wain
Wain

Reputation: 119021

Would it be possible to save the JSON content of customData into a string coredata attribute?

No, because it will be deserialised to a dictionary and there is no converter for that to a string.

You can store it as a dictionary. It you could add a relationship mapping with a dynamic mapping which checks what the keys are and defines the mapping on the fly...

Upvotes: 1

Related Questions