我正在建模没有问题的普通 JSON 对象,但现在为了国际化,我想建模以下场景,其中属性可以是字符串或键/值对字典:
"objects": [{"title": "non internatinalizaed title", ...},
{"title": {"en": "english string", "es": "spanish string"}, ...},
....]
由于我不知道服务器是要发送单个字符串还是多个字符串,所以我正在考虑创建一个这样的模型对象:
@interface I18NString : Object
@property (copy) NSString *forced; // Set when there is no i18n
@property (copy) NSDictionary *strings; // Set with i18n.
- (NSString*)stringValue; // Returns forced or one of strings
类似于 C 结构联合,根据strings
不是 nil,我会在stringValue
方法中选择一个属性或另一个属性。我已经阅读了restkit wiki 中的动态对象映射部分,但我看不到如何使用它来解决这个问题。