我有一個NSMutableDictionary
這是從一個JSON字符串創建的。比較NSArray值與NSMutableDictionary
問題是我需要在NSArray
和NSMutableDictionary
之間做一些非常複雜的數據比較。我無法弄清楚這樣做的有效方法。
字典看起來像這樣:
dictionaryMain
0 = {
key1 = value1;
key2 = value2;
key3 = {
subKey1 = {
subSubKey1 = {
inner1 = apples;
inner2 = oranges;
};
subSubKey2 = {
inner1 = grapes;
inner2 = lemons;
};
subSubKey3 = {
inner1 = mangoes;
inner2 = kiwis;
};
};
};
key4 = {
subKey1 = {
subSubKey1 = {
inner1 = pineapples;
inner2 = apples;
};
subSubKey2 = {
inner1 = oranges;
inner2 = mangoes;
};
};
};
};
1 = {
key1 = value1;
key2 = value2;
key3 = {
subKey1 = {
subSubKey1 = {
inner1 = watermelon;
inner2 = grapes;
};
subSubKey7 = {
inner1 = bananas;
inner2 = oranges;
};
};
};
key4 = {
subKey1 = {
subSubKey5 = {
inner1 = kiwis;
inner2 = mangoes;
};
};
};
};
// ... and so on
我有裏面有一些subSubKey
S的如下陣列arrayOfKeys
:
arrayOfKeys
{
subSubKey5,
subSubKey7,
subSubKey10
}
我需要循環通過我的NSMutableDictionary
並僅選擇那些與arrayOfKeys
中定義的鍵相同的對象。這些選定的對象將被添加到新的字典中。
例如,如果arrayOfKeys
包含subSubKey7
,則對象[1]將從NSMutableDictionary
由於鍵深深浸入內部,具有名稱subSubKey7
選擇。
我試圖找出一個簡單的方法來做到這一點,但我不能想出一個可行的解決方案。我唯一能想到的就是使用很多嵌套循環和髒快速代碼。
我花了兩天的時間來解決這個問題。這個問題的任何解決方案,傢伙?
謝謝!
如果你可以重構json以包含對象1作爲subkey7的值,或者如下面的建議某些函數說明如果子鍵= x,返回對象,否則再次調用函數 – aug2uag