我正在创建一个发布" Photo"具有元数据字典的对象,该元数据字典包括照片的EXIF数据作为Photo对象中的字典,但元数据字典似乎没有包含在JSON帖子中。我猜这是因为你不应该映射任意字典,而应该把它们变成对象。问题是我不知道这本字典中的密钥是什么,因此我无法将密钥转换为其他字段,如示例中所示。任何有关更好的方法的帮助或建议将不胜感激。谢谢!
这是我尝试映射的课程:
@interface Photo : NSObject
@property (nonatomic) UInt64 user;
@property (nonatomic) UInt64 id;
@property (nonatomic, retain) NSString *time_taken;
@property (nonatomic, retain) NSDictionary *metadata;
@end
请求代码
Photo *peanutPhoto = [[DFPeanutPhoto alloc] initWithDFPhoto:photo];
NSData *thumbnailData = UIImageJPEGRepresentation(photo.thumbnail, IMAGE_UPLOAD_JPEG_QUALITY);
NSMutableURLRequest *request = [self.objectManager
multipartFormRequestWithObject:peanutPhoto
method:RKRequestMethodPOST
path:@"photos/"
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:thumbnailData name:@"file"
fileName:@"thumbnail.jpg"
mimeType:@"image/jpg"];
}];
RKObjectRequestOperation *requestOperation = [self.objectManager objectRequestOperationWithRequest:request success:nil failure:nil];
[self.objectManager enqueueObjectRequestOperation:requestOperation];
以下是跟踪日志
2014-05-01 15:47:50.136 69891:3507] D restkit.object_mapping:RKMappingOperation.m:952 Starting mapping operation...
2014-05-01 15:47:50.137 69891:3907] D restkit.object_mapping:RKMappingOperation.m:952 Starting mapping operation...
2014-05-01 15:47:50.138 69891:3907] T restkit.object_mapping:RKMappingOperation.m:953 Performing mapping operation: <RKMappingOperation 0x10ca585e0> for '__NSDictionaryM' object. Mapping values from object Photo: user:59 id:0 time_taken:2014-04-14T16:42:13Z metadata:{
ColorModel = RGB;
Depth = 8;
PixelHeight = 1136;
PixelWidth = 640;
"{DFCameraRollExtras}" = {
DateTimeCreated = "2014:04:14 16:42:13";
};
"{PNG}" = {
InterlaceType = 0;
};
} ((null)) to object {
} with object mapping (null)
2014-05-01 15:47:50.137 69891:3507] T restkit.object_mapping:RKMappingOperation.m:953 Performing mapping operation: <RKMappingOperation 0x10ef62310> for '__NSDictionaryM' object. Mapping values from object Photo: user:59 id:0 time_taken:2014-04-15T15:11:31Z metadata:{
ColorModel = RGB;
DPIHeight = 240;
DPIWidth = 240;
Depth = 8;
PixelHeight = 1208;
PixelWidth = 3264;
"{DFCameraRollExtras}" = {
DateTimeCreated = "2014:04:15 15:11:31";
};
"{ExifAux}" = {
LensInfo = (
"4.12",
"4.12",
"2.2",
"2.2"
);
LensModel = "iPhone 5s back camera 4.12mm f/2.2";
};
"{Exif}" = {
ApertureValue = "2.275007044237813";
BrightnessValue = "9.726902173913043";
ColorSpace = 0;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = "2014:04:15 15:11:31";
DateTimeOriginal = "2014:04:15 15:11:31";
ExifVersion = (
2,
3
);
ExposureMode = 0;
ExposureProgram = 0;
ExposureTime = "0.0007142857142857143";
FNumber = "2.2";
Flash = 0;
FlashPixVersion = (
1,
0
);
FocalLenIn35mmFilm = 0;
FocalLength = "4.12";
ISOSpeedRatings = (
0
);
LensMake = Apple;
LensModel = "iPhone 5s back camera 4.12mm f/2.2";
LensSpecification = (
"4.12",
"4.12",
"2.2",
"2.2"
);
MeteringMode = 0;
PixelXDimension = 0;
PixelYDimension = 0;
SceneCaptureType = 0;
SceneType = 1;
SensingMethod = 0;
ShutterSpeedValue = "10.4512105649303";
SubjectArea = (
1631,
1223,
1795,
1077
);
SubsecTimeDigitized = 755;
SubsecTimeOriginal = 755;
WhiteBalance = 0;
};
"{TIFF}" = {
DateTime = "2014:04:16 11:37:00";
Make = Apple;
Model = "iPhone 5s";
ResolutionUnit = 0;
Software = "Adobe Photoshop Lightroom 5.4 (Macintosh)";
XResolution = 240;
YResolution = 240;
};
} ((null)) to object {
} with object mapping (null)
2014-05-01 15:47:50.138 69891:3907] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'user' to 'user'
2014-05-01 15:47:50.139 69891:3507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'user' to 'user'
2014-05-01 15:47:50.139 69891:3907] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'user' to 'user'. Value: 59
2014-05-01 15:47:50.139 69891:5e03] D restkit.object_mapping:RKPropertyInspector.m:130 Cached property inspection for Class 'NSMutableDictionary': {
fileHFSFlags = {
isPrimitive = 1;
keyValueCodingClass = NSNumber;
name = fileHFSFlags;
};
fileHFSResourceForkSize = {
isPrimitive = 1;
keyValueCodingClass = NSNumber;
name = fileHFSResourceForkSize;
};
}
2014-05-01 15:47:50.140 69891:3507] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'user' to 'user'. Value: 59
2014-05-01 15:47:50.140 69891:3907] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'id' to 'id'
2014-05-01 15:47:50.140 69891:5e03] D restkit.object_mapping:RKPropertyInspector.m:130 Cached property inspection for Class 'Photo': {
id = {
isPrimitive = 1;
keyValueCodingClass = NSNumber;
name = id;
};
metadata = {
isPrimitive = 0;
keyValueCodingClass = NSDictionary;
name = metadata;
};
"time_taken" = {
isPrimitive = 0;
keyValueCodingClass = NSString;
name = "time_taken";
};
user = {
isPrimitive = 1;
keyValueCodingClass = NSNumber;
name = user;
};
}
2014-05-01 15:47:50.140 69891:3907] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'id' to 'id'. Value: 0
2014-05-01 15:47:50.140 69891:3507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'id' to 'id'
2014-05-01 15:47:50.141 69891:3507] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'id' to 'id'. Value: 0
2014-05-01 15:47:50.141 69891:3907] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'time_taken' to 'time_taken'
2014-05-01 15:47:50.142 69891:3907] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'time_taken' to 'time_taken'. Value: 2014-04-14T16:42:13Z
2014-05-01 15:47:50.142 69891:3507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'time_taken' to 'time_taken'
2014-05-01 15:47:50.142 69891:3907] D restkit.object_mapping:RKMappingOperation.m:1021 Finished mapping operation successfully...
2014-05-01 15:47:50.142 69891:3507] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'time_taken' to 'time_taken'. Value: 2014-04-15T15:11:31Z
2014-05-01 15:47:50.143 69891:3507] D restkit.object_mapping:RKMappingOperation.m:1021 Finished mapping operation successfully...
2014-05-01 15:47:50:265 69891:5e03]
答案 0 :(得分:0)
我认为您需要为字典使用关系和嵌套映射。使用RKDynamicMapping
,以便它可以检查元数据的键并创建一个定制的映射,只需使用键数组。