Nested objects in NSDictionary with RestKit

后端 未结 2 658
小鲜肉
小鲜肉 2021-01-14 06:11

I have a JSON document which contains objects with known schema in an object with unknown keys and I\'ll like to map that with RestKit. Let me explain this:

         


        
相关标签:
2条回答
  • 2021-01-14 06:29

    Maybe check out JSONKit https://github.com/johnezang/JSONKit to create a NSDictionary from your JSON document.

    0 讨论(0)
  • 2021-01-14 06:33

    You could do something like this:

    RKObjectMapping* mapping = [RKDynamicObjectMapping dynamicMapping];
    mapping.objectMappingForDataBlock = ^(id data) {
        NSDictionary* object = [data objectForKey: @"object"];
        NSArray* keys = [object allKeys];
    
        RKObjectMapping* dataMapping = [RKObjectMapping objectMapping];
        //Use the keys to define mapping
        return dataMapping;
    };
    
    0 讨论(0)
提交回复
热议问题