2013-02-21 61 views
1

我造型沒有問題的正常JSON對象,但現在國際化我想下面的場景,其中一個屬性可以是一個字符串或鍵/值對的字典型號:如何將不同的JSON輸入映射到RestKit中的同一對象?

"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 

取決於strings是不是nil我會選擇一個類似C結構的結合,財產或其他在stringValue方法。我已閱讀restkit wiki中的Dynamic object mapping部分,但我無法看到如何使用它來解決此問題。

回答

0

你試圖建模的是一對多的關係,其中許多可能是500,1或0.所以,沒關係服務器發送一個NSDictionary只有一個鍵/值(或者甚至0,儘管我猜測你的許多關係是1..n而不是0..n)

相關問題