0

我有想要映射到模型类的 json

{
 "type": "FeatureCollection",
 "features": [
 {
   "geometry": {
     "coordinates": [100.0, 0.0, 129, 1356044399]
   },
   "properties": {
    "name": "My first name",
    "description": "Popular place"
   }
 },
 {
   "geometry": {
     "coordinates": [100.0, 1.0, 127, 1356045399]
   },
   "properties": {
    "name": "My second TIP",
    "description": "Even more popular place"
   }
 }
 ]
}

我想把它放到一个像这样的模型类中:

@property longitude (taken from coordinates index 0)
@property latitude (taken from coordinates index 1)
@property name
@property description
4

1 回答 1

2

好吧,我想出的解决方案如下:

两种型号:

@interface WTFeaturesModel
@property (nonatomic, strong) NSString *type;
@property (nonatomic, strong) NSArray *features;

@interface WTFeatureModel
@property (nonatomic, strong) NSDictionary *properties;
@property (nonatomic, strong) NSDictionary *geometry;

模型映射:

[featureMapping addAttributeMappingsFromArray:@[@"properties", @"geometry"]];

[featuresMapping addAttributeMappingsFromArray:@[ @"type"]];
[featuresMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"features" toKeyPath:@"features" withMapping:featureMapping]];

在我创建了这些模型之后,我必须将数据映射到具有正确属性的另一个模型。无论如何,这使得映射工作......

于 2013-01-29T10:25:57.853 回答